From eb760ee92896a32e902c9bac128a96a611df4333 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 21 Aug 2026 13:18:55 +0200 Subject: [PATCH] Cover how a view's selection follows the focus in and out of a context Nothing said that a context leaving the stack takes its selection with it, which the work coming up is about to make the rule for every view. Two places already depend on it and are held together by hand: switching repos, where the view focused in the repo being left is not the one focused in the repo being entered, and tabbing from the suggestions list back to the prompt, which replaces the top of the stack rather than popping it. Co-authored-by: Claude Opus 5 (1M context) --- pkg/integration/tests/test_list.go | 2 + ...suggestions_selection_follows_the_focus.go | 42 ++++++++++++++++ .../ui/switch_repo_moves_the_selection.go | 48 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 pkg/integration/tests/ui/suggestions_selection_follows_the_focus.go create mode 100644 pkg/integration/tests/ui/switch_repo_moves_the_selection.go diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 5ac4bdcba..434eba2b6 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -526,6 +526,8 @@ var tests = []*components.IntegrationTest{ ui.ReloadSidePanels, ui.ReorderSidePanels, ui.SubCommitsScrollPositionIsReset, + ui.SuggestionsSelectionFollowsTheFocus, + ui.SwitchRepoMovesTheSelection, ui.SwitchTabFromMenu, ui.SwitchTabWithPanelJumpKeys, undo.UndoCheckoutAndDrop, diff --git a/pkg/integration/tests/ui/suggestions_selection_follows_the_focus.go b/pkg/integration/tests/ui/suggestions_selection_follows_the_focus.go new file mode 100644 index 000000000..793c58bf8 --- /dev/null +++ b/pkg/integration/tests/ui/suggestions_selection_follows_the_focus.go @@ -0,0 +1,42 @@ +package ui + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SuggestionsSelectionFollowsTheFocus = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "The suggestions list only shows a selection while it, rather than the prompt, has the focus", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell. + EmptyCommit("one"). + NewBranch("branch-to-checkout") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Press(keys.Branches.CheckoutBranchByName) + + t.ExpectPopup().Prompt(). + Title(Equals("Branch name:")). + Type("branch-to"). + SuggestionTopLines(Contains("branch-to-checkout")) + + t.Views().Suggestions().SelectionIsHidden() + + t.Views().Prompt().Press(keys.Universal.TogglePanel) + t.Views().Suggestions(). + IsFocused(). + SelectionIsActive(). + Press(keys.Universal.TogglePanel) + + t.Views().Prompt().IsFocused() + t.Views().Suggestions().SelectionIsHidden() + + t.Views().Prompt().Press(keys.Universal.Return) + t.Views().Branches().IsFocused() + }, +}) diff --git a/pkg/integration/tests/ui/switch_repo_moves_the_selection.go b/pkg/integration/tests/ui/switch_repo_moves_the_selection.go new file mode 100644 index 000000000..eb7c4b2df --- /dev/null +++ b/pkg/integration/tests/ui/switch_repo_moves_the_selection.go @@ -0,0 +1,48 @@ +package ui + +import ( + "path/filepath" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var SwitchRepoMovesTheSelection = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "The selection follows the focus of the repo being switched to, rather than the one being left", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + otherRepo, _ := filepath.Abs("../other") + config.GetAppState().RecentRepos = []string{otherRepo} + }, + SetupRepo: func(shell *Shell) { + shell.CloneNonBare("other") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + switchToRepo := func(repo string) { + t.GlobalPress(keys.Universal.OpenRecentRepos) + t.ExpectPopup().Menu().Title(Equals("Recent repositories")). + Lines( + Contains(repo).IsSelected(), + Contains("Cancel"), + ).Confirm() + t.Views().Status().Content(Contains(repo + " → master")) + } + + t.Views().Branches(). + Focus(). + SelectionIsActive() + + // The other repo has its own focus, which is the files panel it starts in + switchToRepo("other") + t.Views().Files().IsFocused() + t.Views().Branches().SelectionIsHidden() + + // And coming back, this repo still has the focus we left it with + switchToRepo("repo") + t.Views().Branches(). + IsFocused(). + SelectionIsActive() + t.Views().Files().SelectionIsHidden() + }, +})