diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-05 10:31:07 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 226985bf7602763f7578ef236bdc4cec3a1494e9 (patch) | |
tree | 3a12b9d41099902e411fe32df3b79d31e8a8f375 /pkg/gui/keybindings.go | |
parent | 2db463681564e8db945cd6811fc633545ee9fd83 (diff) |
refactor keybindings
Diffstat (limited to 'pkg/gui/keybindings.go')
-rw-r--r-- | pkg/gui/keybindings.go | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 159965c1b..68b878a13 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1355,16 +1355,16 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding { }, } + keybindingsOpts := types.KeybindingsOpts{ + GetKey: gui.getKey, + Config: config, + Guards: guards, + } + + // global bindings for _, controller := range []types.IController{ - gui.Controllers.LocalCommits, - gui.Controllers.Submodules, - gui.Controllers.Files, - gui.Controllers.Remotes, - gui.Controllers.Menu, - gui.Controllers.Bisect, - gui.Controllers.Undo, gui.Controllers.Sync, - gui.Controllers.Tags, + gui.Controllers.Undo, } { context := controller.Context() viewName := "" @@ -1375,27 +1375,17 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding { contextKeys = []string{string(context.GetKey())} } - for _, binding := range controller.Keybindings(gui.getKey, config, guards) { + for _, binding := range controller.GetKeybindings(keybindingsOpts) { binding.Contexts = contextKeys binding.ViewName = viewName bindings = append(bindings, binding) } } - // while migrating we'll continue providing keybindings from the list contexts themselves. - // for each controller we add above we need to remove the corresponding list context from here. - for _, listContext := range []types.IListContext{ - gui.State.Contexts.Branches, - gui.State.Contexts.RemoteBranches, - gui.State.Contexts.ReflogCommits, - gui.State.Contexts.SubCommits, - gui.State.Contexts.Stash, - gui.State.Contexts.CommitFiles, - gui.State.Contexts.Suggestions, - } { - viewName := listContext.GetViewName() - contextKey := listContext.GetKey() - for _, binding := range listContext.Keybindings(gui.getKey, config, guards) { + for _, context := range gui.allContexts() { + viewName := context.GetViewName() + contextKey := context.GetKey() + for _, binding := range context.GetKeybindings(keybindingsOpts) { binding.Contexts = []string{string(contextKey)} binding.ViewName = viewName bindings = append(bindings, binding) |