diff --git a/pkg/gui/controllers/options_menu_action.go b/pkg/gui/controllers/options_menu_action.go index f757ba0a1..341fe8fb3 100644 --- a/pkg/gui/controllers/options_menu_action.go +++ b/pkg/gui/controllers/options_menu_action.go @@ -18,23 +18,33 @@ func (self *OptionsMenuAction) Call() error { return nil } - bindings := self.getBindings(ctx) + local, global, navigation := self.getBindings(ctx) - menuItems := lo.Map(bindings, func(binding *types.Binding, _ int) *types.MenuItem { - return &types.MenuItem{ - OpensMenu: binding.OpensMenu, - Label: binding.Description, - OnPress: func() error { - if binding.Handler == nil { - return nil + menuItems := []*types.MenuItem{} + + appendBindings := func(bindings []*types.Binding, section *types.MenuSection) { + menuItems = append(menuItems, + lo.Map(bindings, func(binding *types.Binding, _ int) *types.MenuItem { + return &types.MenuItem{ + OpensMenu: binding.OpensMenu, + Label: binding.Description, + OnPress: func() error { + if binding.Handler == nil { + return nil + } + + return binding.Handler() + }, + Key: binding.Key, + Tooltip: binding.Tooltip, + Section: section, } + })...) + } - return binding.Handler() - }, - Key: binding.Key, - Tooltip: binding.Tooltip, - } - }) + appendBindings(local, &types.MenuSection{Title: self.c.Tr.KeybindingsMenuSectionLocal, Column: 1}) + appendBindings(global, &types.MenuSection{Title: self.c.Tr.KeybindingsMenuSectionGlobal, Column: 1}) + appendBindings(navigation, &types.MenuSection{Title: self.c.Tr.KeybindingsMenuSectionNavigation, Column: 1}) return self.c.Menu(types.CreateMenuOptions{ Title: self.c.Tr.Keybindings, @@ -44,7 +54,8 @@ func (self *OptionsMenuAction) Call() error { }) } -func (self *OptionsMenuAction) getBindings(context types.Context) []*types.Binding { +// Returns three slices of bindings: local, global, and navigation +func (self *OptionsMenuAction) getBindings(context types.Context) ([]*types.Binding, []*types.Binding, []*types.Binding) { var bindingsGlobal, bindingsPanel, bindingsNavigation []*types.Binding bindings, _ := self.c.GetInitialKeybindingsWithCustomCommands() @@ -61,14 +72,7 @@ func (self *OptionsMenuAction) getBindings(context types.Context) []*types.Bindi } } - resultBindings := []*types.Binding{} - resultBindings = append(resultBindings, uniqueBindings(bindingsPanel)...) - // adding a separator between the panel-specific bindings and the other bindings - resultBindings = append(resultBindings, &types.Binding{}) - resultBindings = append(resultBindings, uniqueBindings(bindingsGlobal)...) - resultBindings = append(resultBindings, uniqueBindings(bindingsNavigation)...) - - return resultBindings + return uniqueBindings(bindingsPanel), uniqueBindings(bindingsGlobal), uniqueBindings(bindingsNavigation) } // We shouldn't really need to do this. We should define alternative keys for the same diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 50b62549f..93909cbdc 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -388,6 +388,9 @@ type TranslationSet struct { Panel string Keybindings string KeybindingsLegend string + KeybindingsMenuSectionLocal string + KeybindingsMenuSectionGlobal string + KeybindingsMenuSectionNavigation string RenameBranch string SetUnsetUpstream string NewGitFlowBranchPrompt string @@ -986,6 +989,9 @@ func EnglishTranslationSet() TranslationSet { ConflictsResolved: "All merge conflicts resolved. Continue?", Continue: "Continue", Keybindings: "Keybindings", + KeybindingsMenuSectionLocal: "Local", + KeybindingsMenuSectionGlobal: "Global", + KeybindingsMenuSectionNavigation: "Navigation", RebasingTitle: "Rebase '{{.checkedOutBranch}}' onto '{{.ref}}'", RebasingFromBaseCommitTitle: "Rebase '{{.checkedOutBranch}}' from marked base onto '{{.ref}}'", SimpleRebase: "Simple rebase",