mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Handle field adjust of pending active fields
* yasnippet.el (yas--on-field-overlay-modification): Call yas--advance-end-maybe on all pending active snippets in case of stacked expansion. (yas-next-field): Get current snippet according to active field bounds. * yasnippet-tests.el (nested-snippet-expansion-4): New test.
This commit is contained in:
parent
ffc733d4cf
commit
eeb05f0910
@ -1066,6 +1066,26 @@ hello ${1:$(when (stringp yas-text) (funcall func yas-text))} foo${1:$$(concat \
|
||||
(ert-simulate-command '(yas-next-field-or-maybe-expand))
|
||||
(should (string= (buffer-string) "\\sqrt[3]{\\sqrt[5]{2}}")))))
|
||||
|
||||
(ert-deftest nested-snippet-expansion-4 ()
|
||||
"See Github #959."
|
||||
(let ((yas-triggers-in-field t))
|
||||
(yas-with-snippet-dirs
|
||||
'((".emacs.d/snippets"
|
||||
("text-mode"
|
||||
("ch" . "<-${1:ch}"))))
|
||||
(yas-reload-all)
|
||||
(text-mode)
|
||||
(yas-minor-mode +1)
|
||||
(yas-expand-snippet "ch$0\n")
|
||||
(ert-simulate-command '(yas-expand))
|
||||
(ert-simulate-command '(forward-char 2))
|
||||
(ert-simulate-command '(yas-expand))
|
||||
(yas-mock-insert "abc")
|
||||
(ert-simulate-command '(yas-next-field-or-maybe-expand))
|
||||
(yas-mock-insert "def")
|
||||
(ert-simulate-command '(yas-next-field-or-maybe-expand))
|
||||
(should (string= (buffer-string) "<-<-abcdef\n")))))
|
||||
|
||||
|
||||
;;; Loading
|
||||
;;;
|
||||
|
15
yasnippet.el
15
yasnippet.el
@ -3326,8 +3326,9 @@ Otherwise delegate to `yas-next-field'."
|
||||
If there's none, exit the snippet."
|
||||
(interactive)
|
||||
(unless arg (setq arg 1))
|
||||
(let* ((snippet (car (yas-active-snippets)))
|
||||
(active-field (overlay-get yas--active-field-overlay 'yas--field))
|
||||
(let* ((active-field (overlay-get yas--active-field-overlay 'yas--field))
|
||||
(snippet (car (yas-active-snippets (yas--field-start active-field)
|
||||
(yas--field-end active-field))))
|
||||
(target-field (yas--find-next-field arg snippet active-field)))
|
||||
(yas--letenv (yas--snippet-expand-env snippet)
|
||||
;; Apply transform to active field.
|
||||
@ -3745,7 +3746,15 @@ field start. This hook does nothing if an undo is in progress."
|
||||
;; We delete text starting from the END of insertion.
|
||||
(yas--skip-and-clear field end))
|
||||
(setf (yas--field-modified-p field) t)
|
||||
(yas--advance-end-maybe field (overlay-end overlay))
|
||||
;; Adjust any pending active fields in case of stacked
|
||||
;; expansion.
|
||||
(let ((pfield field)
|
||||
(psnippets (yas-active-snippets beg end)))
|
||||
(while (and pfield psnippets)
|
||||
(let ((psnippet (pop psnippets)))
|
||||
(cl-assert (memq pfield (yas--snippet-fields psnippet)))
|
||||
(yas--advance-end-maybe pfield (overlay-end overlay))
|
||||
(setq pfield (yas--snippet-previous-active-field psnippet)))))
|
||||
(save-excursion
|
||||
(yas--field-update-display field))
|
||||
(yas--update-mirrors snippet)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user