From: Oleh Krehel Date: Tue, 6 Oct 2015 14:52:09 +0000 (+0200) Subject: ivy.el (ivy--filter): Anchor only for swiper X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/126158d5e5f9eff0a23aa07b1adebdbdd5465770 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 --- diff --git a/ivy-test.el b/ivy-test.el index 76f2ddeb7..384cd4d51 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 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 73ebbfa0d..6fbb84c39 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)