mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
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.
This commit is contained in:
parent
4a6d923c9d
commit
acf2cdd03e
@ -160,20 +160,17 @@
|
|||||||
(ert-simulate-command '(yas-prev-field))
|
(ert-simulate-command '(yas-prev-field))
|
||||||
(should (looking-at "brother"))))
|
(should (looking-at "brother"))))
|
||||||
|
|
||||||
(ert-deftest dont-clear-on-yank-issue-515 ()
|
(ert-deftest do-clear-on-yank-issue-515 ()
|
||||||
"A yank shouldn't clear and unmodified field." ; or should it? -- jt
|
"A yank should clear an unmodified field."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(yas-minor-mode 1)
|
(yas-minor-mode 1)
|
||||||
(yas-expand-snippet "my ${1:kid brother} from another ${2:mother}")
|
(yas-expand-snippet "my ${1:kid brother} from another ${2:mother}")
|
||||||
|
(yas-mock-yank "little sibling")
|
||||||
(yas-mock-yank "little")
|
|
||||||
(yas-mock-insert " ")
|
|
||||||
|
|
||||||
(should (string= (yas--buffer-contents)
|
(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-next-field))
|
||||||
(ert-simulate-command '(yas-prev-field))
|
(ert-simulate-command '(yas-prev-field))
|
||||||
(should (looking-at "little kid brother"))))
|
(should (looking-at "little sibling"))))
|
||||||
|
|
||||||
|
|
||||||
;;; Snippet expansion and character escaping
|
;;; Snippet expansion and character escaping
|
||||||
|
14
yasnippet.el
14
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)
|
(defun yas--skip-and-clear-field-p (field _beg _end &optional _length)
|
||||||
"Tell if newly modified FIELD should be cleared and skipped.
|
"Tell if newly modified FIELD should be cleared and skipped.
|
||||||
BEG, END and LENGTH like overlay modification hooks."
|
BEG, END and LENGTH like overlay modification hooks."
|
||||||
(and (eq this-command 'self-insert-command)
|
(and (not (yas--field-modified-p field))
|
||||||
(not (yas--field-modified-p field))
|
(= (point) (yas--field-start 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)
|
(defun yas--on-field-overlay-modification (overlay after? beg end &optional length)
|
||||||
"Clears the field and updates mirrors, conditionally.
|
"Clears the field and updates mirrors, conditionally.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user