Skip to content

Commit b237462

Browse files
authored
Allow switching direction on ex-search shorthand repeat (#1485)
1 parent 200da7f commit b237462

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

evil-search.el

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ any error conditions."
966966
offset (or offset evil-ex-search-offset)))
967967
(when (zerop (length pat))
968968
(throw 'done (list 'empty-pattern pat offset)))
969-
(let (search-result)
969+
(let (new-dir repeat-last search-result)
970970
(while (> count 0)
971971
(let ((result (evil-ex-find-next pat direction
972972
(not evil-search-wrap))))
@@ -986,21 +986,21 @@ any error conditions."
986986
;; single `?' or `/' means repeat last pattern and finish
987987
((= 1 (length next-pat))
988988
(evil-ex-search-goto-offset offset)
989-
(setq count 1
989+
(setq new-dir (if (string= "/" next-pat) 'forward 'backward)
990+
count (if (eq direction new-dir) 1 2)
990991
pattern-string orig-pat
991-
direction (if (string= "/" next-pat) 'forward 'backward)))
992+
direction new-dir))
992993
;; next non-empty pattern, next search iteration
993994
(t
994995
(evil-ex-search-goto-offset offset)
995-
(setq count 1
996-
pattern-string (if (and (<= 2 (length next-pat))
997-
(member (substring next-pat 0 2) '("//" "??")))
998-
;; double `?' or `/' means repeat last pattern
996+
(setq new-dir (if (= (aref next-pat 0) ?/) 'forward 'backward)
997+
repeat-last (and (<= 2 (length next-pat))
998+
(member (substring next-pat 0 2) '("//" "??")))
999+
count (if (or (eq direction new-dir) (not repeat-last)) 1 2)
1000+
pattern-string (if repeat-last
9991001
(concat orig-pat (substring next-pat 1))
10001002
(substring next-pat 1))
1001-
direction (if (= (aref next-pat 0) ?/)
1002-
'forward
1003-
'backward)))))))))
1003+
direction new-dir))))))))
10041004

10051005
(defun evil-ex-search-update-pattern (_beg _end _range)
10061006
"Update the current search pattern."

evil-tests.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7527,7 +7527,14 @@ if no previous selection")
75277527
("/alpha/;//")
75287528
"alpha bravo charlie delta charlie alpha bravo [a]lpha"
75297529
("?charlie?;?")
7530-
"alpha bravo [c]harlie delta charlie alpha bravo alpha"))))
7530+
"alpha bravo [c]harlie delta charlie alpha bravo alpha")
7531+
(ert-info ("including when switching direction")
7532+
(evil-test-buffer
7533+
"[a]lpha bravo charlie delta charlie alpha bravo alpha"
7534+
("/bravo/;?")
7535+
"alpha bravo charlie delta charlie alpha [b]ravo alpha"
7536+
("?alpha?;//")
7537+
"alpha bravo charlie delta charlie alpha bravo [a]lpha")))))
75317538

75327539
(ert-deftest evil-test-ex-search-word ()
75337540
"Test search for word under point."

0 commit comments

Comments
 (0)