branch: master
commit 126158d5e5f9eff0a23aa07b1adebdbdd5465770
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy--filter): Anchor only for swiper
* ivy-test.el (ivy-read): Add tests. Except for `swiper', when the input
changes `ivy-index' should usually be 0.
Fixes #231
---
ivy-test.el | 11 ++++++++++-
ivy.el | 36 +++++++++++++++++++-----------------
2 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 76f2dde..384cd4d 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -59,7 +59,16 @@
(should (equal
(ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
"z C-m")
- "z")))
+ "z"))
+ (should (equal
+ (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
+ "y <backspace> C-m")
+ "blue"))
+ (should (equal
+ (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")))
(ert-deftest swiper--re-builder ()
(setq swiper--width 4)
diff --git a/ivy.el b/ivy.el
index 73ebbfa..6fbb84c 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1553,23 +1553,25 @@ CANDIDATES are assumed to be static."
res))))
(tail (nthcdr ivy--index ivy--old-cands))
idx)
- (when (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
- (unless (and (not (equal re-str ivy--old-re))
- (or (setq ivy--index
- (or
- (cl-position (if (and (> (length re-str) 0)
- (eq ?^ (aref re-str
0)))
- (substring re-str 1)
- re-str) cands
- :test #'equal)
- (and ivy--directory
- (cl-position
- (concat re-str "/") cands
- :test #'equal))))))
- (while (and tail (null idx))
- ;; Compare with eq to handle equal duplicates in cands
- (setq idx (cl-position (pop tail) cands)))
- (setq ivy--index (or idx 0))))
+ (if (eq (ivy-state-unwind ivy-last) 'swiper--cleanup)
+ (when (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
+ (unless (and (not (equal re-str ivy--old-re))
+ (or (setq ivy--index
+ (or
+ (cl-position (if (and (> (length re-str)
0)
+ (eq ?^ (aref
re-str 0)))
+ (substring re-str 1)
+ re-str) cands
+ :test #'equal)
+ (and ivy--directory
+ (cl-position
+ (concat re-str "/") cands
+ :test #'equal))))))
+ (while (and tail (null idx))
+ ;; Compare with eq to handle equal duplicates in cands
+ (setq idx (cl-position (pop tail) cands)))
+ (setq ivy--index (or idx 0))))
+ (setq ivy-index 0))
(when (and (string= name "") (not (equal ivy--old-re "")))
(setq ivy--index
(or (cl-position (ivy-state-preselect ivy-last)