Show the current search match in full where it overlaps other matches

If the search string can overlap itself, as "aa" can in "aaaa", the
matches overlap too. A cell that is part of two matches shows as part
of the first one. If the second one is the current match, some of its
cells then show in the color of the other matches, and it is hard to
tell where the current match is.

Show a cell as part of the current match whenever it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-11-12 11:28:00 +01:00
co-authored by Claude Opus 5.5
parent e64b209aed
commit b9e0861dfc
2 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -126,7 +126,7 @@ func TestDrawSearchMatches(t *testing.T) {
drawSearchHighlights(v))
}
// Where matches overlap, a cell is highlighted as part of the first match it is in.
// Where matches overlap, the current one shows in full.
func TestDrawOverlappingSearchMatches(t *testing.T) {
WithSimulationScreen(t, 14, 6)
@@ -139,7 +139,7 @@ func TestDrawOverlappingSearchMatches(t *testing.T) {
assert.Equal(t, 3, total)
assert.Equal(t,
[]string{"##*#......"},
[]string{"#**#......"},
drawSearchHighlights(v))
}
+3 -2
View File
@@ -2178,7 +2178,8 @@ func (s *searcher) matchWalker(firstY int) searchMatchWalker {
}
// matchAt returns whether the cell at content column x of view line y is part of a
// search match.
// search match. If it is part of several overlapping matches, and the current match is
// one of them, it counts as part of the current one.
func (w *searchMatchWalker) matchAt(x, y int) searchMatch {
for w.index < len(w.positions) {
pos := w.positions[w.index]
@@ -2191,7 +2192,7 @@ func (w *searchMatchWalker) matchAt(x, y int) searchMatch {
if w.index == len(w.positions) || !w.positions[w.index].contains(x, y) {
return noSearchMatch
}
if w.index == w.currentIndex {
if w.positions[w.currentIndex].contains(x, y) {
return currentSearchMatch
}
return otherSearchMatch