From 56b6c5af3133cfa6b24aede00291d4dd51f64c1c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 13 Oct 2026 16:26:38 +0200 Subject: [PATCH] Stop at the end of the diff when jumping to a file from a panel With gui.scrollPastBottom set to false, picking the last file of a long diff from the jump-to-file menu of the commits panel scrolls that file to the top of the view. This leaves blank space below the end of the diff. A jump in a pane that isn't focused puts the file at the top of the view and leaves it to the layout to stop at the end of the diff. But the layout doesn't do this while the view is loading. Picking an item from the menu closes the menu first, and the commits panel starts a re-render of the diff as it gets the focus back. So the view is loading when the jump happens, and the layout corrects the position only in a later pass after the re-render has finished. For a long diff the re-render never finishes; a later commit fixes this. Clicking a file in the diffstat doesn't close a menu, so it doesn't have the problem. Stop the jump at the last screenful of the diff, as a jump in the focused pane does. Like that one, it stops there whatever gui.scrollPastBottom is set to. The diff in click_a_file_in_a_diff_stat_that_comes_first fits on screen, so the jump doesn't scroll it any more. Make it longer than the view. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/controllers/helpers/diff_line_selection.go | 7 ++++--- .../click_a_file_in_a_diff_stat_that_comes_first.go | 6 +++++- .../main_view/jump_to_the_last_file_of_a_long_diff.go | 3 --- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/gui/controllers/helpers/diff_line_selection.go b/pkg/gui/controllers/helpers/diff_line_selection.go index 4cc86d5b8..ff9a9d2c9 100644 --- a/pkg/gui/controllers/helpers/diff_line_selection.go +++ b/pkg/gui/controllers/helpers/diff_line_selection.go @@ -65,8 +65,9 @@ func (self *DiffLineHelper) EstablishSelection(mainContext *context.MainContext, // PlaceNavigationTarget moves the pane's selection to the row a jump found, bringing // it on screen if it isn't already. With no selection to move — a pane that isn't -// focused, or one showing a diff with nothing selectable in it — the row goes to the -// top of the view instead, that being all a jump can do there. +// focused, or one showing a diff with nothing selectable in it — all a jump can do is +// scroll the row to the top of the view, or as close to the top as the end of the diff +// allows. // // alignTop asks for the target to become the view's top line, so that everything that // begins there is on screen. It only applies to a target the view has to scroll to: a @@ -84,7 +85,7 @@ func (self *DiffLineHelper) PlaceNavigationTarget( ) { view := pane.GetView() if !view.Highlight { - view.SetOrigin(0, target) + view.SetOrigin(0, originYWithTargetAtTop(pane, target)) return } if alignTop { diff --git a/pkg/integration/tests/main_view/click_a_file_in_a_diff_stat_that_comes_first.go b/pkg/integration/tests/main_view/click_a_file_in_a_diff_stat_that_comes_first.go index 2d459e21d..1f1f71fa1 100644 --- a/pkg/integration/tests/main_view/click_a_file_in_a_diff_stat_that_comes_first.go +++ b/pkg/integration/tests/main_view/click_a_file_in_a_diff_stat_that_comes_first.go @@ -1,6 +1,8 @@ package main_view import ( + "strings" + "github.com/jesseduffield/lazygit/pkg/config" . "github.com/jesseduffield/lazygit/pkg/integration/components" ) @@ -23,7 +25,9 @@ var ClickAFileInADiffStatThatComesFirst = NewIntegrationTest(NewIntegrationTestA SetupRepo: func(shell *Shell) { shell.CreateFileAndAdd("aaa.txt", "one\n") shell.Commit("one") - shell.CreateFileAndAdd("zzz.txt", "one\n") + // Longer than the view, so that the diff can be scrolled to put aaa.txt at the + // top. + shell.CreateFileAndAdd("zzz.txt", strings.Repeat("line\n", 40)) shell.Commit("two") }, Run: func(t *TestDriver, keys config.KeybindingConfig) { diff --git a/pkg/integration/tests/main_view/jump_to_the_last_file_of_a_long_diff.go b/pkg/integration/tests/main_view/jump_to_the_last_file_of_a_long_diff.go index fad3a21db..e2d3c0745 100644 --- a/pkg/integration/tests/main_view/jump_to_the_last_file_of_a_long_diff.go +++ b/pkg/integration/tests/main_view/jump_to_the_last_file_of_a_long_diff.go @@ -45,9 +45,6 @@ var JumpToTheLastFileOfALongDiff = NewIntegrationTest(NewIntegrationTestArgs{ // The view shows the last screenful of the diff: the end of long.txt's diff, // and all of short.txt's below it. t.Views().Main(). - /* EXPECTED: TopVisibleLine(Equals("+line5994")) - ACTUAL: */ - TopVisibleLine(Equals("diff --git a/short.txt b/short.txt")) }, })