diff --git a/pkg/gocui/view.go b/pkg/gocui/view.go index 4395c7a21..643163a2a 100644 --- a/pkg/gocui/view.go +++ b/pkg/gocui/view.go @@ -638,8 +638,15 @@ func (v *View) IsSearching() bool { return v.searcher.searchString != "" } +// nearestSearchPosition returns the current match if it is on the cursor's line. +// Otherwise it returns the first match on that line, or else the last match above it, +// or the first match if there is none above. func (v *View) nearestSearchPosition() int { currentLineIndex := v.cy + v.oy + if v.searcher.searchPositions[v.searcher.currentSearchIndex].Y == currentLineIndex { + return v.searcher.currentSearchIndex + } + lastSearchPos := 0 for i, pos := range v.searcher.searchPositions { if pos.Y == currentLineIndex { diff --git a/pkg/integration/tests/commit/search_keeps_the_second_match_on_a_line_on_refresh.go b/pkg/integration/tests/commit/search_keeps_the_second_match_on_a_line_on_refresh.go index c16ae0e78..dc66e9e75 100644 --- a/pkg/integration/tests/commit/search_keeps_the_second_match_on_a_line_on_refresh.go +++ b/pkg/integration/tests/commit/search_keeps_the_second_match_on_a_line_on_refresh.go @@ -37,17 +37,11 @@ var SearchKeepsTheSecondMatchOnALineOnRefresh = NewIntegrationTest(NewIntegratio t.GlobalPress(keys.Universal.Refresh) t.Views().Search().Content( - /* EXPECTED: Contains("matches for 'needle' (2 of 3)")) - ACTUAL: */ - Contains("matches for 'needle' (1 of 3)")) }). Press(keys.Universal.NextMatch). SelectedLines( - /* EXPECTED: Contains("commit 02 needle"), - ACTUAL: */ - Contains("commit 04 needle and needle"), ) }, })