diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-13 10:01:35 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:28:42 +0200 |
commit | cf27fd827b0b9cd7d3701d3c9b23b6dd5345ca58 (patch) | |
tree | 54bd04cdac7745d6f5722aaf4eb363a9b09365c1 /pkg | |
parent | a7c97400c69f641683f38fb7cf11eb8b18e11882 (diff) |
Clear keybinding functions in resetHelpersAndControllers
When switching to a repo that was open before, the context tree is reused, so
before adding keybinding functions to those contexts again, we need to clear the
old ones.
Diffstat (limited to 'pkg')
-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/tests/ui/keybinding_suggestions_when_switching_repos.go | 3 |
4 files changed, 10 insertions, 3 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/tests/ui/keybinding_suggestions_when_switching_repos.go b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go index 2bf4e53c9..62cb16b60 100644 --- a/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go +++ b/pkg/integration/tests/ui/keybinding_suggestions_when_switching_repos.go @@ -37,9 +37,6 @@ var KeybindingSuggestionsWhenSwitchingRepos = NewIntegrationTest(NewIntegrationT switchToRepo("repo") t.Views().Options().Content( - /* EXPECTED: Equals("Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc>")) - ACTUAL (all keybindings appear twice): */ - Equals("Commit: c | Stash: s | Reset: D | Commit: c | Stash: s | Reset: D | Keybindings: ? | Cancel: <esc> | Keybindings: ? | Cancel: <esc>")) }, }) |