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) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-09-05 10:17:20 +02:00
parent 0505e778b3
commit 04a7ae3ec8
2 changed files with 21 additions and 0 deletions

View file

@ -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.

View file

@ -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"))
},
})