branch: master commit 9500b000fde22cdb59ad178ae7c4920e866ba329 Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
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. --- yasnippet-tests.el | 7 +++++-- yasnippet.el | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index b0906d5..c5fd376 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -38,14 +38,17 @@ (ert-deftest field-navigation () (with-temp-buffer (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) "brother from another mother")) - (should (looking-at "brother")) (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")) (ert-simulate-command '(yas-prev-field)) + (should (looking-at "another")) + (ert-simulate-command '(yas-prev-field)) (should (looking-at "brother")))) (ert-deftest simple-mirror () diff --git a/yasnippet.el b/yasnippet.el index 79861ee..cae33a0 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3079,8 +3079,7 @@ Otherwise delegate to `yas-next-field'." (and (not (eq field active)) (yas--field-probably-deleted-p snippet field))) (yas--snippet-fields snippet)))) - (if (>= n 0) (nth n (memq active live-fields)) - (car (last (memq active (reverse live-fields)) (- n)))))) + (nth (abs n) (memq active (if (>= n 0) live-fields (reverse live-fields)))))) (defun yas-next-field (&optional arg) "Navigate to the ARGth next field.