Skip to content

Commit

Permalink
ivy-test.el (swiper-isearch-backward): Goto old match on DEL
Browse files Browse the repository at this point in the history
* ivy-test.el (swiper-isearch-backward-backspace): Add test.

Fixes #2125
  • Loading branch information
abo-abo committed Jul 17, 2019
1 parent f5508e5 commit 6e50ab6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 16 additions & 0 deletions ivy-test.el
Expand Up @@ -1149,6 +1149,22 @@ a buffer visiting a file."
("C-r" "defun\\|defvar" "C-n RET"))
"(defun foo)\nasdf\n(|defvar bar)")))

(ert-deftest swiper-isearch-backward-backspace ()
(should
(string=
(ivy-with-text
"(while (when |))"
(global-set-key (kbd "C-r") #'swiper-isearch-backward)
("C-r" "whi" "" "RET"))
"(while (|when ))"))
(should
(string=
(ivy-with-text
"(while (when |))"
(global-set-key (kbd "C-r") #'isearch-backward-regexp)
("C-r" "whi" "" "RET"))
"(while (|when ))")))

(ert-deftest swiper-isearch-case-fold ()
(should
(string=
Expand Down
10 changes: 4 additions & 6 deletions swiper.el
Expand Up @@ -1323,12 +1323,10 @@ come back to the same place as when \"a\" was initially entered.")
(while (funcall (if swiper--isearch-backward #'re-search-backward #'re-search-forward) re nil t)
(when (swiper-match-usable-p)
(unless idx-found
(when (if swiper--isearch-backward
;; test if match is before point
(<= (match-beginning 0) (cdar swiper--isearch-point-history))
(or
;; test if match is at or after point
(eq (match-beginning 0) pt-hist)
(when (or
(eq (match-beginning 0) pt-hist)

This comment has been minimized.

Copy link
@andyleejordan

andyleejordan Jul 18, 2019

Contributor

@abo-abo This behavior isn't entirely correct. isearch-backward explicitly does not check if the point is at a matching candidate, it always goes to the first before the point. I'll open a PR with a new test.

This comment has been minimized.

Copy link
@andyleejordan

andyleejordan Jul 18, 2019

Contributor

I wrote what I mean in #2150

(if swiper--isearch-backward
(<= (match-beginning 0) (cdar swiper--isearch-point-history))
(>= (match-beginning 0) (cdar swiper--isearch-point-history))))
(push (cons str (match-beginning 0)) swiper--isearch-point-history)
(setq idx-found idx)))
Expand Down

0 comments on commit 6e50ab6

Please sign in to comment.