Skip to content

Commit 2898f15

Browse files
authored
made FindNext and FindPrevious work with empty matches (#3572)
1 parent aa0fefc commit 2898f15

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/action/actions.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,14 @@ func (h *BufPane) FindNext() bool {
12111211
match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex)
12121212
if err != nil {
12131213
InfoBar.Error(err)
1214+
} else if found && searchLoc == match[0] && match[0] == match[1] {
1215+
// skip empty match at present cursor location
1216+
if searchLoc == h.Buf.End() {
1217+
searchLoc = h.Buf.Start()
1218+
} else {
1219+
searchLoc = searchLoc.Move(1, h.Buf)
1220+
}
1221+
match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex)
12141222
}
12151223
if found {
12161224
h.Cursor.SetSelectionStart(match[0])
@@ -1240,6 +1248,14 @@ func (h *BufPane) FindPrevious() bool {
12401248
match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex)
12411249
if err != nil {
12421250
InfoBar.Error(err)
1251+
} else if found && searchLoc == match[0] && match[0] == match[1] {
1252+
// skip empty match at present cursor location
1253+
if searchLoc == h.Buf.Start() {
1254+
searchLoc = h.Buf.End()
1255+
} else {
1256+
searchLoc = searchLoc.Move(-1, h.Buf)
1257+
}
1258+
match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex)
12431259
}
12441260
if found {
12451261
h.Cursor.SetSelectionStart(match[0])

0 commit comments

Comments
 (0)