Fix field navigation in the backwards direction

* yasnippet.el (yas--find-next-field): For negative N, actually give the
Nth previous field, not the 1st field.
* yasnippet-tests.el (field-navigation): Add a 3rd field, and test
calling `yas-prev-field' while on it.

Fixes #722.
This commit is contained in:
Noam Postavsky 2016-07-13 17:03:30 -04:00
parent 0db65ee0bb
commit 9500b000fd
2 changed files with 6 additions and 4 deletions

View File

@ -38,14 +38,17 @@
(ert-deftest field-navigation () (ert-deftest field-navigation ()
(with-temp-buffer (with-temp-buffer
(yas-minor-mode 1) (yas-minor-mode 1)
(yas-expand-snippet "${1:brother} from another ${2:mother}") (yas-expand-snippet "${1:brother} from ${2:another} ${3:mother}")
(should (string= (yas--buffer-contents) (should (string= (yas--buffer-contents)
"brother from another mother")) "brother from another mother"))
(should (looking-at "brother")) (should (looking-at "brother"))
(ert-simulate-command '(yas-next-field-or-maybe-expand)) (ert-simulate-command '(yas-next-field-or-maybe-expand))
(should (looking-at "another"))
(ert-simulate-command '(yas-next-field-or-maybe-expand))
(should (looking-at "mother")) (should (looking-at "mother"))
(ert-simulate-command '(yas-prev-field)) (ert-simulate-command '(yas-prev-field))
(should (looking-at "another"))
(ert-simulate-command '(yas-prev-field))
(should (looking-at "brother")))) (should (looking-at "brother"))))
(ert-deftest simple-mirror () (ert-deftest simple-mirror ()

View File

@ -3079,8 +3079,7 @@ Otherwise delegate to `yas-next-field'."
(and (not (eq field active)) (and (not (eq field active))
(yas--field-probably-deleted-p snippet field))) (yas--field-probably-deleted-p snippet field)))
(yas--snippet-fields snippet)))) (yas--snippet-fields snippet))))
(if (>= n 0) (nth n (memq active live-fields)) (nth (abs n) (memq active (if (>= n 0) live-fields (reverse live-fields))))))
(car (last (memq active (reverse live-fields)) (- n))))))
(defun yas-next-field (&optional arg) (defun yas-next-field (&optional arg)
"Navigate to the ARGth next field. "Navigate to the ARGth next field.