Bring the current search match back into range when the matches change

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-09-05 10:00:35 +02:00
parent b54318e80c
commit 4c90bc334c
2 changed files with 5 additions and 3 deletions

View file

@ -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)
}

View file

@ -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