mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
Closes #290: problem when advancing the start of a mirror-in-field
* Rewrote 'yas--update-mirrors' * Added unit test * Advancing is done exceptionally in 'yas--update-mirrors' not 'yas--mirror-update-display' and just before we need to re-update the mirror-in-field. * Alternative to prior point would be to have fields carry a reference to their child mirrors.
This commit is contained in:
parent
8a26ab0a31
commit
9503c332f5
@ -95,6 +95,16 @@
|
|||||||
(should (string= (yas--buffer-contents)
|
(should (string= (yas--buffer-contents)
|
||||||
"brother from another bla!"))))
|
"brother from another bla!"))))
|
||||||
|
|
||||||
|
(ert-deftest mirrors-adjacent-to-fields-with-nested-mirrors ()
|
||||||
|
(with-temp-buffer)
|
||||||
|
(yas-minor-mode 1)
|
||||||
|
(yas-expand-snippet "<%= f.submit \"${1:Submit}\"${2:$(and (yas-text) \", :disable_with => '\")}${2:$1ing...}${2:$(and (yas-text) \"'\")} %>")
|
||||||
|
(should (string= (yas--buffer-contents)
|
||||||
|
"<%= f.submit \"Submit\", :disable_with => 'Submiting...' %>"))
|
||||||
|
(ert-simulate-command `(yas-mock-insert "Send"))
|
||||||
|
(should (string= (yas--buffer-contents)
|
||||||
|
"<%= f.submit \"Send\", :disable_with => 'Sending...' %>")))
|
||||||
|
|
||||||
;; (ert-deftest in-snippet-undo ()
|
;; (ert-deftest in-snippet-undo ()
|
||||||
;; (with-temp-buffer
|
;; (with-temp-buffer
|
||||||
;; (yas-minor-mode 1)
|
;; (yas-minor-mode 1)
|
||||||
|
54
yasnippet.el
54
yasnippet.el
@ -4139,27 +4139,39 @@ When multiple expressions are found, only the last one counts."
|
|||||||
(defun yas--update-mirrors (snippet)
|
(defun yas--update-mirrors (snippet)
|
||||||
"Updates all the mirrors of SNIPPET."
|
"Updates all the mirrors of SNIPPET."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let* ((fields (copy-list (yas--snippet-fields snippet)))
|
(dolist (field-and-mirror (sort
|
||||||
(field (car fields)))
|
;; make a list of ((F1 . M1) (F1 . M2) (F2 . M3) (F2 . M4) ...)
|
||||||
(while field
|
;; where F is the field that M is mirroring
|
||||||
(dolist (mirror (yas--field-mirrors field))
|
;;
|
||||||
(let ((mirror-parent-field (yas--mirror-parent-field mirror)))
|
(mapcan #'(lambda (field)
|
||||||
;; updatte this mirror
|
(mapcar #'(lambda (mirror)
|
||||||
;;
|
(cons field mirror))
|
||||||
(yas--mirror-update-display mirror field)
|
(yas--field-mirrors field)))
|
||||||
;; for mirrors-in-fields: schedule a possible
|
(yas--snippet-fields snippet))
|
||||||
;; parent field for reupdting later on
|
;; then sort this list so that entries with mirrors with parent
|
||||||
;;
|
;; fields appear before. This was important for fixing #290, and
|
||||||
(when mirror-parent-field
|
;; luckily also handles the case where a mirror in a field causes
|
||||||
(add-to-list 'fields mirror-parent-field 'append #'eq))
|
;; another mirror to need reupdating
|
||||||
;; `yas--place-overlays' is needed if the active field and
|
;;
|
||||||
;; protected overlays have been changed because of insertions
|
#'(lambda (field-and-mirror1 field-and-mirror2)
|
||||||
;; in `yas--mirror-update-display'
|
(yas--mirror-parent-field (cdr field-and-mirror1)))))
|
||||||
;;
|
(let* ((field (car field-and-mirror))
|
||||||
(when (eq field (yas--snippet-active-field snippet))
|
(mirror (cdr field-and-mirror))
|
||||||
(yas--place-overlays snippet field))))
|
(parent-field (yas--mirror-parent-field mirror)))
|
||||||
(setq fields (cdr fields))
|
;; before updating a mirror with a parent-field, maybe advance
|
||||||
(setq field (car fields))))))
|
;; its start (#290)
|
||||||
|
;;
|
||||||
|
(when parent-field
|
||||||
|
(yas--advance-start-maybe mirror (yas--fom-start parent-field)))
|
||||||
|
;; update this mirror
|
||||||
|
;;
|
||||||
|
(yas--mirror-update-display mirror field)
|
||||||
|
;; `yas--place-overlays' is needed if the active field and
|
||||||
|
;; protected overlays have been changed because of insertions
|
||||||
|
;; in `yas--mirror-update-display'
|
||||||
|
;;
|
||||||
|
(when (eq field (yas--snippet-active-field snippet))
|
||||||
|
(yas--place-overlays snippet field))))))
|
||||||
|
|
||||||
(defun yas--mirror-update-display (mirror field)
|
(defun yas--mirror-update-display (mirror field)
|
||||||
"Update MIRROR according to FIELD (and mirror transform)."
|
"Update MIRROR according to FIELD (and mirror transform)."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user