From 4c90bc334c5792f88c6e19d42197278402aad168 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 5 Sep 2026 10:00:35 +0200 Subject: [PATCH] Bring the current search match back into range when the matches change Co-authored-by: Claude Opus 5 (1M context) --- pkg/gocui/search_test.go | 3 --- pkg/gocui/view.go | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/gocui/search_test.go b/pkg/gocui/search_test.go index ef87f7e46..f2ecccec4 100644 --- a/pkg/gocui/search_test.go +++ b/pkg/gocui/search_test.go @@ -31,9 +31,6 @@ func TestSearchStatusAfterTheMatchesChange(t *testing.T) { writeLines(v, "match", "other", "other") index, total = v.GetSearchStatus() - /* EXPECTED: assert.Equal(t, 0, index) - ACTUAL: */ - assert.Equal(t, 2, index) assert.Equal(t, 1, total) } diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index 6e7b35520..294b34f25 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -1431,6 +1431,11 @@ func (v *View) updateSearchPositions() { } } } + + // The content may hold fewer matches than it did, so the current one is brought + // back into range: readers index the positions by it. + v.searcher.currentSearchIndex = min(v.searcher.currentSearchIndex, + max(0, len(v.searcher.searchPositions)-1)) } // IsTainted tells us if the view is tainted