From 04a7ae3ec8418043ffad8a1a464a0f26b7003fde Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 5 Sep 2026 10:17:20 +0200 Subject: [PATCH] Read a view that is being searched to the end when it renders again Opening the search prompt reads the whole of the view's content, so that the search counts every match in it. Rendering the content again reads only as much as the scrollbar needs, so the matches below that point are lost. The "x of y" drops to what the shortened content holds, and grows again as the user scrolls far enough to load more. Read to the end while a search is on, the way opening the prompt does. Co-authored-by: Claude Opus 5 (1M context) --- pkg/gui/view_helpers.go | 12 ++++++++++++ .../tests/filter_and_search/search_a_long_diff.go | 9 +++++++++ 2 files changed, 21 insertions(+) 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")) }, })