1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

fixed keybinding display in merge_panel.go

This commit is contained in:
David Chen
2020-01-07 09:50:25 -08:00
parent 66c7672a0c
commit 529ba45cc7
3 changed files with 36 additions and 48 deletions

View File

@ -21,7 +21,7 @@ type Binding struct {
// GetDisplayStrings returns the display string of a file
func (b *Binding) GetDisplayStrings(isFocused bool) []string {
return []string{b.GetKey(), b.Description}
return []string{GetKeyDisplay(b.Key), b.Description}
}
var keyMapReversed = map[gocui.Key]string{
@ -43,10 +43,10 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyEnd: "end",
gocui.KeyPgup: "pgup",
gocui.KeyPgdn: "pgdown",
gocui.KeyArrowUp: "up",
gocui.KeyArrowDown: "down",
gocui.KeyArrowLeft: "left",
gocui.KeyArrowRight: "right",
gocui.KeyArrowUp: "",
gocui.KeyArrowDown: "",
gocui.KeyArrowLeft: "",
gocui.KeyArrowRight: "",
gocui.KeyTab: "tab", // ctrl+i
gocui.KeyEnter: "enter", // ctrl+m
gocui.KeyEsc: "esc", // ctrl+[, ctrl+3
@ -83,48 +83,6 @@ var keyMapReversed = map[gocui.Key]string{
gocui.KeyCtrl8: "ctrl+8",
}
// GetKey is a function.
func (b *Binding) GetKey() string {
key := 0
switch b.Key.(type) {
case rune:
key = int(b.Key.(rune))
case gocui.Key:
value, ok := keyMapReversed[b.Key.(gocui.Key)]
if ok {
return value
}
key = int(b.Key.(gocui.Key))
}
// special keys
switch key {
case 27:
return "esc"
case 13:
return "enter"
case 32:
return "space"
case 65514:
return "►"
case 65515:
return "◄"
case 65517:
return "▲"
case 65516:
return "▼"
case 65508:
return "PgUp"
case 65507:
return "PgDn"
case 9:
return "tab"
}
return string(key)
}
var keymap = map[string]interface{}{
"<c-a>": gocui.KeyCtrlA,
"<c-b>": gocui.KeyCtrlB,
@ -195,6 +153,28 @@ var keymap = map[string]interface{}{
"<right>": gocui.KeyArrowRight,
}
func (gui *Gui) getKeyDisplay(name string) string {
key := gui.getKey(name)
return GetKeyDisplay(key)
}
func GetKeyDisplay(key interface{}) string {
keyInt := 0
switch key.(type) {
case rune:
keyInt = int(key.(rune))
case gocui.Key:
value, ok := keyMapReversed[key.(gocui.Key)]
if ok {
return value
}
keyInt = int(key.(gocui.Key))
}
return string(keyInt)
}
func (gui *Gui) getKey(name string) interface{} {
key := gui.Config.GetUserConfig().GetString("keybinding." + name)
if len(key) > 1 {