From b9e0861dfc1f13a260e6ed40e0550841efb3df3c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 9 Nov 2026 16:23:19 +0100 Subject: [PATCH] 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 --- pkg/gocui/search_test.go | 4 ++-- pkg/gocui/view.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/gocui/search_test.go b/pkg/gocui/search_test.go index efbc53afd..5e4c60e51 100644 --- a/pkg/gocui/search_test.go +++ b/pkg/gocui/search_test.go @@ -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)) } diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index 29adf3fc8..fd6b67ce9 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -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