Skip to content

Commit f20d442

Browse files
authored
Fix 1482 addr wraparound (#1483)
* Add wraparound to `evil-ex-re-fwd` + `evil-ex-re-bwd` Fixes a bug noted in #1482 * Tests for 1482
1 parent 6dbb2d8 commit f20d442

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

evil-ex.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,11 @@ Returns the line number of the match."
814814
(save-excursion
815815
(set-text-properties 0 (length pattern) nil pattern)
816816
(evil-move-end-of-line)
817-
(and (re-search-forward pattern nil t)
818-
(line-number-at-pos (1- (match-end 0))))))
817+
(if (re-search-forward pattern nil t)
818+
(line-number-at-pos (1- (match-end 0)))
819+
(goto-char (point-min))
820+
(and (re-search-forward pattern nil t)
821+
(line-number-at-pos (1- (match-end 0)))))))
819822
(invalid-regexp
820823
(evil-ex-echo (cadr err))
821824
nil)))
@@ -828,8 +831,11 @@ Returns the line number of the match."
828831
(save-excursion
829832
(set-text-properties 0 (length pattern) nil pattern)
830833
(evil-move-beginning-of-line)
831-
(and (re-search-backward pattern nil t)
832-
(line-number-at-pos (match-beginning 0)))))
834+
(if (re-search-backward pattern nil t)
835+
(line-number-at-pos (match-beginning 0))
836+
(goto-char (point-max))
837+
(and (re-search-backward pattern nil t)
838+
(line-number-at-pos (match-beginning 0))))))
833839
(invalid-regexp
834840
(evil-ex-echo (cadr err))
835841
nil)))

evil-tests.el

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7846,7 +7846,33 @@ maybe we need one line more with some text\n")
78467846
(evil-test-buffer
78477847
"line1\nline2\nline3\nli[n]e4\nline5\n"
78487848
(":2,4move.")
7849-
"line1\nline2\nline3\n[l]ine4\nline5\n")))
7849+
"line1\nline2\nline3\n[l]ine4\nline5\n"))
7850+
(ert-info ("Move to backwards line, searching forwards (wrapping around)")
7851+
(evil-test-buffer
7852+
"
7853+
Target
7854+
Other line
7855+
[S]ource
7856+
"
7857+
(":move/Target/")
7858+
"
7859+
Target
7860+
[S]ource
7861+
Other line
7862+
"))
7863+
(ert-info ("Move to forwards line, searching backwards (wrapping around)")
7864+
(evil-test-buffer
7865+
"
7866+
Target
7867+
[O]ther line
7868+
Source
7869+
"
7870+
(":move?Source?")
7871+
"
7872+
Target
7873+
Source
7874+
[O]ther line
7875+
")))
78507876

78517877
(ert-deftest evil-test-write ()
78527878
:tags '(evil ex)

evil-types.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ If visual state is inactive then those values are nil."
380380
"Ex line number."
381381
(list
382382
(and (evil-ex-p)
383-
(let ((expr (evil-ex-parse evil-ex-argument)))
383+
(let ((expr (evil-ex-parse evil-ex-argument)))
384384
(if (eq (car expr) 'evil-goto-line)
385385
(save-excursion
386386
(goto-char evil-ex-point)

0 commit comments

Comments
 (0)