1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Add sections (local, global) to the keybindings menu

This commit is contained in:
Stefan Haller 2023-08-08 13:27:50 +02:00
parent 6d4df57393
commit 37381b610d
2 changed files with 33 additions and 23 deletions

View File

@ -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

View File

@ -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",