From 2236c8d8d91d38db34eb223457b199a718e8a802 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 19 Aug 2026 09:53:12 +0200 Subject: [PATCH] Add a test for a main pane coming back after being emptied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A pane the render has nothing to show is emptied, but keeps the scroll position it was left at and its claim to the render it was showing. So when it comes back — the file it was showing before is selected again — its content is rendered under the same command it already had, which is taken for the content the view is showing, and the user is left partway down a diff they have only just been given. Co-authored-by: Claude Opus 5 (1M context) --- .../pane_shown_again_starts_at_the_top.go | 64 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 65 insertions(+) create mode 100644 pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go diff --git a/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go b/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go new file mode 100644 index 000000000..1219543f8 --- /dev/null +++ b/pkg/integration/tests/file/pane_shown_again_starts_at_the_top.go @@ -0,0 +1,64 @@ +package file + +import ( + "fmt" + "strings" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var PaneShownAgainStartsAtTheTop = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "A pane that was emptied while it wasn't shown starts at the top when it comes back, rather than where it was left", + ExtraCmdArgs: []string{}, + Skip: false, + Width: 120, + Height: 30, + SetupConfig: func(cfg *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + lines := make([]string, 40) + for i := range lines { + lines[i] = fmt.Sprintf("line%02d", i+1) + } + shell.CreateFileAndAdd("file1", strings.Join(lines, "\n")+"\n") + shell.CreateFileAndAdd("file2", "one\n") + shell.Commit("one") + + // More staged changes in file1 than fit in the pane they are shown in, so that + // there is a position in it to lose, plus an unstaged change to give the file a + // second pane. + for i := range lines { + lines[i] = strings.ToUpper(lines[i]) + } + shell.UpdateFileAndAdd("file1", strings.Join(lines, "\n")+"\n") + shell.UpdateFile("file1", strings.Join(lines, "\n")+"unstaged\n") + + shell.UpdateFile("file2", "two\n") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + NavigateToLine(Contains("file1")) + + t.Views().Secondary(). + IsVisible(). + Title(Equals("Staged changes")). + ScrollWheelDown(). + ScrollWheelDown(). + OriginYAtLeast(1) + + // A file with nothing staged leaves that pane with nothing to show, so it goes + // away and is emptied. + t.Views().Files().NavigateToLine(Contains("file2")) + t.Views().Secondary().IsInvisible() + + t.Views().Files().NavigateToLine(Contains("file1")) + t.Views().Secondary(). + IsVisible(). + Content(Contains("+LINE40")). + /* EXPECTED: + OriginY(0) + ACTUAL: */ + OriginYAtLeast(1) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index dee2c7ffe..ec6ab3f54 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -252,6 +252,7 @@ var tests = []*components.IntegrationTest{ file.ExcludeWithoutInfoDir, file.Gitignore, file.GitignoreSpecialCharacters, + file.PaneShownAgainStartsAtTheTop, file.RememberCommitMessageAfterFail, file.RenameSimilarityThresholdChange, file.RenamedFiles,