branch: master commit acf2cdd03e504e5ed6bcced842c213c23d75740f Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Decide field clearing commands based on delsel * yasnippet.el (yas--skip-and-clear-field-p): Check `delete-selection' of `this-command'. Fix #644, close #645. --- yasnippet-tests.el | 13 +++++-------- yasnippet.el | 14 +++++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 040c83a..cf8ace9 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -160,20 +160,17 @@ (ert-simulate-command '(yas-prev-field)) (should (looking-at "brother")))) -(ert-deftest dont-clear-on-yank-issue-515 () - "A yank shouldn't clear and unmodified field." ; or should it? -- jt +(ert-deftest do-clear-on-yank-issue-515 () + "A yank should clear an unmodified field." (with-temp-buffer (yas-minor-mode 1) (yas-expand-snippet "my ${1:kid brother} from another ${2:mother}") - - (yas-mock-yank "little") - (yas-mock-insert " ") - + (yas-mock-yank "little sibling") (should (string= (yas--buffer-contents) - "my little kid brother from another mother")) + "my little sibling from another mother")) (ert-simulate-command '(yas-next-field)) (ert-simulate-command '(yas-prev-field)) - (should (looking-at "little kid brother")))) + (should (looking-at "little sibling")))) ;;; Snippet expansion and character escaping diff --git a/yasnippet.el b/yasnippet.el index 5a14529..59285a6 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3388,9 +3388,17 @@ Move the overlay, or create it if it does not exit." (defun yas--skip-and-clear-field-p (field _beg _end &optional _length) "Tell if newly modified FIELD should be cleared and skipped. BEG, END and LENGTH like overlay modification hooks." - (and (eq this-command 'self-insert-command) - (not (yas--field-modified-p field)) - (= (point) (yas--field-start field)))) + (and (not (yas--field-modified-p field)) + (= (point) (yas--field-start field)) + (require 'delsel) + ;; `yank' sets `this-command' to t during execution. + (let ((clearp (get (if (commandp this-command) this-command + this-original-command) + 'delete-selection))) + (when (and (not (memq clearp '(yank supersede kill))) + (functionp clearp)) + (setq clearp (funcall clearp))) + clearp))) (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) "Clears the field and updates mirrors, conditionally.