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