mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-23 22:24:51 +02:00
clean up keybindings menu
This commit is contained in:
@@ -15,64 +15,66 @@ import (
|
||||
)
|
||||
|
||||
var keyMapReversed = map[gocui.Key]string{
|
||||
gocui.KeyF1: "f1",
|
||||
gocui.KeyF2: "f2",
|
||||
gocui.KeyF3: "f3",
|
||||
gocui.KeyF4: "f4",
|
||||
gocui.KeyF5: "f5",
|
||||
gocui.KeyF6: "f6",
|
||||
gocui.KeyF7: "f7",
|
||||
gocui.KeyF8: "f8",
|
||||
gocui.KeyF9: "f9",
|
||||
gocui.KeyF10: "f10",
|
||||
gocui.KeyF11: "f11",
|
||||
gocui.KeyF12: "f12",
|
||||
gocui.KeyInsert: "insert",
|
||||
gocui.KeyDelete: "delete",
|
||||
gocui.KeyHome: "home",
|
||||
gocui.KeyEnd: "end",
|
||||
gocui.KeyPgup: "pgup",
|
||||
gocui.KeyPgdn: "pgdown",
|
||||
gocui.KeyArrowUp: "▲",
|
||||
gocui.KeyArrowDown: "▼",
|
||||
gocui.KeyArrowLeft: "◄",
|
||||
gocui.KeyArrowRight: "►",
|
||||
gocui.KeyTab: "tab", // ctrl+i
|
||||
gocui.KeyBacktab: "shift+tab",
|
||||
gocui.KeyEnter: "enter", // ctrl+m
|
||||
gocui.KeyAltEnter: "alt+enter",
|
||||
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
|
||||
gocui.KeyBackspace: "backspace", // ctrl+h
|
||||
gocui.KeyCtrlSpace: "ctrl+space", // ctrl+~, ctrl+2
|
||||
gocui.KeyCtrlSlash: "ctrl+/", // ctrl+_
|
||||
gocui.KeySpace: "space",
|
||||
gocui.KeyCtrlA: "ctrl+a",
|
||||
gocui.KeyCtrlB: "ctrl+b",
|
||||
gocui.KeyCtrlC: "ctrl+c",
|
||||
gocui.KeyCtrlD: "ctrl+d",
|
||||
gocui.KeyCtrlE: "ctrl+e",
|
||||
gocui.KeyCtrlF: "ctrl+f",
|
||||
gocui.KeyCtrlG: "ctrl+g",
|
||||
gocui.KeyCtrlJ: "ctrl+j",
|
||||
gocui.KeyCtrlK: "ctrl+k",
|
||||
gocui.KeyCtrlL: "ctrl+l",
|
||||
gocui.KeyCtrlN: "ctrl+n",
|
||||
gocui.KeyCtrlO: "ctrl+o",
|
||||
gocui.KeyCtrlP: "ctrl+p",
|
||||
gocui.KeyCtrlQ: "ctrl+q",
|
||||
gocui.KeyCtrlR: "ctrl+r",
|
||||
gocui.KeyCtrlS: "ctrl+s",
|
||||
gocui.KeyCtrlT: "ctrl+t",
|
||||
gocui.KeyCtrlU: "ctrl+u",
|
||||
gocui.KeyCtrlV: "ctrl+v",
|
||||
gocui.KeyCtrlW: "ctrl+w",
|
||||
gocui.KeyCtrlX: "ctrl+x",
|
||||
gocui.KeyCtrlY: "ctrl+y",
|
||||
gocui.KeyCtrlZ: "ctrl+z",
|
||||
gocui.KeyCtrl4: "ctrl+4", // ctrl+\
|
||||
gocui.KeyCtrl5: "ctrl+5", // ctrl+]
|
||||
gocui.KeyCtrl6: "ctrl+6",
|
||||
gocui.KeyCtrl8: "ctrl+8",
|
||||
gocui.KeyF1: "f1",
|
||||
gocui.KeyF2: "f2",
|
||||
gocui.KeyF3: "f3",
|
||||
gocui.KeyF4: "f4",
|
||||
gocui.KeyF5: "f5",
|
||||
gocui.KeyF6: "f6",
|
||||
gocui.KeyF7: "f7",
|
||||
gocui.KeyF8: "f8",
|
||||
gocui.KeyF9: "f9",
|
||||
gocui.KeyF10: "f10",
|
||||
gocui.KeyF11: "f11",
|
||||
gocui.KeyF12: "f12",
|
||||
gocui.KeyInsert: "insert",
|
||||
gocui.KeyDelete: "delete",
|
||||
gocui.KeyHome: "home",
|
||||
gocui.KeyEnd: "end",
|
||||
gocui.KeyPgup: "pgup",
|
||||
gocui.KeyPgdn: "pgdown",
|
||||
gocui.KeyArrowUp: "▲",
|
||||
gocui.KeyArrowDown: "▼",
|
||||
gocui.KeyArrowLeft: "◄",
|
||||
gocui.KeyArrowRight: "►",
|
||||
gocui.KeyTab: "tab", // ctrl+i
|
||||
gocui.KeyBacktab: "shift+tab",
|
||||
gocui.KeyEnter: "enter", // ctrl+m
|
||||
gocui.KeyAltEnter: "alt+enter",
|
||||
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
|
||||
gocui.KeyBackspace: "backspace", // ctrl+h
|
||||
gocui.KeyCtrlSpace: "ctrl+space", // ctrl+~, ctrl+2
|
||||
gocui.KeyCtrlSlash: "ctrl+/", // ctrl+_
|
||||
gocui.KeySpace: "space",
|
||||
gocui.KeyCtrlA: "ctrl+a",
|
||||
gocui.KeyCtrlB: "ctrl+b",
|
||||
gocui.KeyCtrlC: "ctrl+c",
|
||||
gocui.KeyCtrlD: "ctrl+d",
|
||||
gocui.KeyCtrlE: "ctrl+e",
|
||||
gocui.KeyCtrlF: "ctrl+f",
|
||||
gocui.KeyCtrlG: "ctrl+g",
|
||||
gocui.KeyCtrlJ: "ctrl+j",
|
||||
gocui.KeyCtrlK: "ctrl+k",
|
||||
gocui.KeyCtrlL: "ctrl+l",
|
||||
gocui.KeyCtrlN: "ctrl+n",
|
||||
gocui.KeyCtrlO: "ctrl+o",
|
||||
gocui.KeyCtrlP: "ctrl+p",
|
||||
gocui.KeyCtrlQ: "ctrl+q",
|
||||
gocui.KeyCtrlR: "ctrl+r",
|
||||
gocui.KeyCtrlS: "ctrl+s",
|
||||
gocui.KeyCtrlT: "ctrl+t",
|
||||
gocui.KeyCtrlU: "ctrl+u",
|
||||
gocui.KeyCtrlV: "ctrl+v",
|
||||
gocui.KeyCtrlW: "ctrl+w",
|
||||
gocui.KeyCtrlX: "ctrl+x",
|
||||
gocui.KeyCtrlY: "ctrl+y",
|
||||
gocui.KeyCtrlZ: "ctrl+z",
|
||||
gocui.KeyCtrl4: "ctrl+4", // ctrl+\
|
||||
gocui.KeyCtrl5: "ctrl+5", // ctrl+]
|
||||
gocui.KeyCtrl6: "ctrl+6",
|
||||
gocui.KeyCtrl8: "ctrl+8",
|
||||
gocui.MouseWheelUp: "mouse wheel up",
|
||||
gocui.MouseWheelDown: "mouse wheel down",
|
||||
}
|
||||
|
||||
var keymap = map[string]interface{}{
|
||||
@@ -249,7 +251,6 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
ViewName: "",
|
||||
Key: opts.GetKey(opts.Config.Universal.OpenRecentRepos),
|
||||
Handler: self.handleCreateRecentReposMenu,
|
||||
Alternative: "<c-r>",
|
||||
Description: self.c.Tr.SwitchRepo,
|
||||
},
|
||||
{
|
||||
@@ -325,6 +326,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
},
|
||||
{
|
||||
ViewName: "status",
|
||||
Contexts: []string{string(context.STATUS_CONTEXT_KEY)},
|
||||
Key: opts.GetKey(opts.Config.Universal.Edit),
|
||||
Handler: self.handleEditConfig,
|
||||
Description: self.c.Tr.EditConfig,
|
||||
@@ -343,24 +345,28 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
},
|
||||
{
|
||||
ViewName: "status",
|
||||
Contexts: []string{string(context.STATUS_CONTEXT_KEY)},
|
||||
Key: opts.GetKey(opts.Config.Universal.OpenFile),
|
||||
Handler: self.handleOpenConfig,
|
||||
Description: self.c.Tr.OpenConfig,
|
||||
},
|
||||
{
|
||||
ViewName: "status",
|
||||
Contexts: []string{string(context.STATUS_CONTEXT_KEY)},
|
||||
Key: opts.GetKey(opts.Config.Status.CheckForUpdate),
|
||||
Handler: self.handleCheckForUpdate,
|
||||
Description: self.c.Tr.LcCheckForUpdate,
|
||||
},
|
||||
{
|
||||
ViewName: "status",
|
||||
Contexts: []string{string(context.STATUS_CONTEXT_KEY)},
|
||||
Key: opts.GetKey(opts.Config.Status.RecentRepos),
|
||||
Handler: self.handleCreateRecentReposMenu,
|
||||
Description: self.c.Tr.SwitchRepo,
|
||||
},
|
||||
{
|
||||
ViewName: "status",
|
||||
Contexts: []string{string(context.STATUS_CONTEXT_KEY)},
|
||||
Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph),
|
||||
Handler: self.handleShowAllBranchLogs,
|
||||
Description: self.c.Tr.LcAllBranchesLogGraph,
|
||||
@@ -729,6 +735,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
Key: opts.GetKey(opts.Config.Universal.ScrollLeft),
|
||||
Handler: self.scrollLeftMain,
|
||||
Description: self.c.Tr.LcScrollLeft,
|
||||
Tag: "navigation",
|
||||
},
|
||||
{
|
||||
ViewName: "main",
|
||||
@@ -736,6 +743,7 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
|
||||
Key: opts.GetKey(opts.Config.Universal.ScrollRight),
|
||||
Handler: self.scrollRightMain,
|
||||
Description: self.c.Tr.LcScrollRight,
|
||||
Tag: "navigation",
|
||||
},
|
||||
{
|
||||
ViewName: "main",
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func (gui *Gui) getBindings(context types.Context) []*types.Binding {
|
||||
var (
|
||||
bindingsGlobal, bindingsPanel []*types.Binding
|
||||
bindingsGlobal, bindingsPanel, bindingsNavigation []*types.Binding
|
||||
)
|
||||
|
||||
bindings, _ := gui.GetInitialKeybindings()
|
||||
@@ -24,18 +24,40 @@ func (gui *Gui) getBindings(context types.Context) []*types.Binding {
|
||||
|
||||
for _, binding := range bindings {
|
||||
if GetKeyDisplay(binding.Key) != "" && binding.Description != "" {
|
||||
if len(binding.Contexts) == 0 {
|
||||
if len(binding.Contexts) == 0 && binding.ViewName == "" {
|
||||
bindingsGlobal = append(bindingsGlobal, binding)
|
||||
} else if binding.Tag == "navigation" {
|
||||
bindingsNavigation = append(bindingsNavigation, binding)
|
||||
} else if utils.IncludesString(binding.Contexts, string(context.GetKey())) {
|
||||
bindingsPanel = append(bindingsPanel, binding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// append dummy element to have a separator between
|
||||
// panel and global keybindings
|
||||
bindingsPanel = append(bindingsPanel, &types.Binding{})
|
||||
return append(bindingsPanel, bindingsGlobal...)
|
||||
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
|
||||
}
|
||||
|
||||
// We shouldn't really need to do this. We should define alternative keys for the same
|
||||
// handler in the keybinding struct.
|
||||
func uniqueBindings(bindings []*types.Binding) []*types.Binding {
|
||||
keys := make(map[string]bool)
|
||||
result := make([]*types.Binding, 0)
|
||||
|
||||
for _, binding := range bindings {
|
||||
if _, ok := keys[binding.Description]; !ok {
|
||||
keys[binding.Description] = true
|
||||
result = append(result, binding)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (gui *Gui) displayDescription(binding *types.Binding) string {
|
||||
|
||||
Reference in New Issue
Block a user