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