diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 5f3e4c2ab..9b2e29c02 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -25,6 +25,18 @@ func (gui *Gui) linesToReadFromCmdTask(v *gocui.View) tasks.LinesToRead { linesForFirstRefresh := height + oy + 10 + // A search counts the matches in everything the view holds, so a re-render of a + // view that is being searched is read all the way to the end (as opening the + // search prompt reads it, see MainViewController.openSearch). Lines left unread + // hold matches the search doesn't know about, and would add themselves to the + // "x of y" as the user scrolled far enough to load them. + if v.IsSearching() { + return tasks.LinesToRead{ + Total: -1, + InitialRefreshAfter: linesForFirstRefresh, + } + } + // We want to read as many lines initially as necessary to let the // scrollbar go to its minimum height, so that the scrollbar thumb doesn't // change size as you scroll down. diff --git a/pkg/integration/tests/filter_and_search/search_a_long_diff.go b/pkg/integration/tests/filter_and_search/search_a_long_diff.go index 6da59ce10..7f2ebf156 100644 --- a/pkg/integration/tests/filter_and_search/search_a_long_diff.go +++ b/pkg/integration/tests/filter_and_search/search_a_long_diff.go @@ -53,5 +53,14 @@ var SearchALongDiff = NewIntegrationTest(NewIntegrationTestArgs{ FilterOrSearch("NEEDLE") t.Views().Search().Content(Contains("matches for 'NEEDLE' (1 of 3)")) + + // Rendering the diff again reads it from the start, and it is read all the + // way down to the matches the search already knows about. + t.Views().Main(). + Press(keys.Universal.IncreaseContextInDiffView). + Tap(func() { + t.ExpectToast(Equals("Changed diff context size to 4")) + }). + Content(Contains("+NEEDLE last")) }, })