diff options
-rw-r--r-- | pkg/gui/context/base_context.go | 5 | ||||
-rw-r--r-- | pkg/gui/controllers.go | 4 | ||||
-rw-r--r-- | pkg/gui/types/context.go | 1 | ||||
-rw-r--r-- | pkg/integration/components/shell.go | 6 | ||||
-rw-r--r-- | pkg/integration/tests/test_list.go | 1 | ||||
-rw-r--r-- | pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go | 42 |
6 files changed, 59 insertions, 0 deletions
diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index beaa61446..dfcced021 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -133,6 +133,11 @@ func (self *BaseContext) AddMouseKeybindingsFn(fn types.MouseKeybindingsFn) { self.mouseKeybindingsFns = append(self.mouseKeybindingsFns, fn) } +func (self *BaseContext) ClearAllBindingsFn() { + self.keybindingsFns = []types.KeybindingsFn{} + self.mouseKeybindingsFns = []types.MouseKeybindingsFn{} +} + func (self *BaseContext) AddOnClickFn(fn func() error) { if fn != nil { self.onClickFn = fn diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index 1dbf9b7d7..d6ac5a268 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -20,6 +20,10 @@ func (gui *Gui) Helpers() *helpers.Helpers { // in the keybinding menu: the earlier that the controller is attached to a context, // the lower in the list the keybindings will appear. func (gui *Gui) resetHelpersAndControllers() { + for _, context := range gui.Contexts().Flatten() { + context.ClearAllBindingsFn() + } + helperCommon := gui.c recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon) reposHelper := helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo) diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 691d5694d..003035fc2 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -74,6 +74,7 @@ type IBaseContext interface { AddKeybindingsFn(KeybindingsFn) AddMouseKeybindingsFn(MouseKeybindingsFn) + ClearAllBindingsFn() // This is a bit of a hack at the moment: we currently only set an onclick function so that // our list controller can come along and wrap it in a list-specific click handler. diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index a8caff77d..01a9caf3a 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -360,6 +360,12 @@ func (self *Shell) Clone(repoName string) *Shell { return self } +func (self *Shell) CloneNonBare(repoName string) *Shell { + self.RunCommand([]string{"git", "clone", ".", "../" + repoName}) + + return self +} + func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell { self.RunCommand([]string{"git", "branch", "--set-upstream-to=" + upstream, branch}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 5fbbfb4e2..cc7fc6ca1 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -315,6 +315,7 @@ var tests = []*components.IntegrationTest{ ui.Accordion, ui.DoublePopup, ui.EmptyMenu, + ui.KeybindingSuggestionsWhenSwitchingRepos, ui.ModeSpecificKeybindingSuggestions, ui.OpenLinkFailure, ui.RangeSelect, diff --git a/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go new file mode 100644 index 000000000..62cb16b60 --- /dev/null +++ b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go @@ -0,0 +1,42 @@ +package ui + +import ( + "path/filepath" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var KeybindingSuggestionsWhenSwitchingRepos = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Show correct keybinding suggestions after switching between repos", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + otherRepo, _ := filepath.Abs("../other") + config.AppState.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().Files().Focus() + t.Views().Options().Content( + Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>")) + + switchToRepo("other") + switchToRepo("repo") + + t.Views().Options().Content( + Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>")) + }, +}) |