branch: master
commit 3699fa9b416ba129c448cb60a1eb016d3a820ee9
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Don't reset the match to first if the current one still works
* 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 | 6 +++++-
ivy.el | 5 ++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 384cd4d..5c77394 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -68,7 +68,11 @@
(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 02b6c73..235aca7 100644
--- 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 "")))