]> code.delx.au - gnu-emacs-elpa/commitdiff
Don't reset the match to first if the current one still works
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 9 Oct 2015 08:44:11 +0000 (10:44 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 9 Oct 2015 08:44:11 +0000 (10:44 +0200)
* ivy.el (ivy--recompute-index): If the old match is still located in
  the current matches after the change in input, keep it selected.

* ivy-test.el (ivy-read): Add test.

Fixes #258

ivy-test.el
ivy.el

index 384cd4d514ce96fe5985f7c2b2949f18488db90d..5c773946726d354932af60d5cd2f928642c6bf03 100644 (file)
            (ivy-with '(let ((ivy-re-builders-alist '((t . ivy--regex-fuzzy))))
                        (ivy-read "pattern: " '("package-list-packages" "something-else")))
                      "plp C-m")
-           "package-list-packages")))
+           "package-list-packages"))
+  (should (equal
+           (ivy-with '(ivy-read "test" '("aaab" "aaac"))
+                     "a C-n <tab> C-m")
+           "aaac")))
 
 (ert-deftest swiper--re-builder ()
   (setq swiper--width 4)
diff --git a/ivy.el b/ivy.el
index 02b6c7302aaf07b8fa1d834bdb7c2d8c93b72c11..235aca7c7f8318b3c190a547d5ed657fd043e64e 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -1612,7 +1612,10 @@ CANDIDATES are assumed to be static."
          (func (or (and caller (cdr (assoc caller ivy-index-functions-alist)))
                    (cdr (assoc t ivy-index-functions-alist))
                    #'ivy-recompute-index-zero)))
-    (setq ivy--index (funcall func re-str cands))
+    (setq ivy--index
+          (or (cl-position (nth ivy--index ivy--old-cands)
+                           cands)
+              (funcall func re-str cands)))
     (when (and (or (string= name "")
                    (string= name "^"))
                (not (equal ivy--old-re "")))