From 2898f1590d7a0588c5ae27753b2d68bd2607156a Mon Sep 17 00:00:00 2001 From: matthias314 <56549971+matthias314@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:52:44 -0500 Subject: [PATCH] made `FindNext` and `FindPrevious` work with empty matches (#3572) --- internal/action/actions.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/internal/action/actions.go b/internal/action/actions.go index 0256865f..21f24620 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1211,6 +1211,14 @@ func (h *BufPane) FindNext() bool { match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex) if err != nil { InfoBar.Error(err) + } else if found && searchLoc == match[0] && match[0] == match[1] { + // skip empty match at present cursor location + if searchLoc == h.Buf.End() { + searchLoc = h.Buf.Start() + } else { + searchLoc = searchLoc.Move(1, h.Buf) + } + match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, true, h.Buf.LastSearchRegex) } if found { h.Cursor.SetSelectionStart(match[0]) @@ -1240,6 +1248,14 @@ func (h *BufPane) FindPrevious() bool { match, found, err := h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex) if err != nil { InfoBar.Error(err) + } else if found && searchLoc == match[0] && match[0] == match[1] { + // skip empty match at present cursor location + if searchLoc == h.Buf.Start() { + searchLoc = h.Buf.End() + } else { + searchLoc = searchLoc.Move(-1, h.Buf) + } + match, found, _ = h.Buf.FindNext(h.Buf.LastSearch, h.Buf.Start(), h.Buf.End(), searchLoc, false, h.Buf.LastSearchRegex) } if found { h.Cursor.SetSelectionStart(match[0])