mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 15:46:26 -04:00
Add config.KeyFromLabel
This commit is contained in:
parent
a5b760f8d1
commit
c455fca062
|
|
@ -73,16 +73,24 @@ var LabelByKey = map[gocui.KeyName]string{
|
|||
|
||||
var KeyByLabel = lo.Invert(LabelByKey)
|
||||
|
||||
func isValidKeybindingKey(key string) bool {
|
||||
runeCount := utf8.RuneCountInString(key)
|
||||
if key == "<disabled>" {
|
||||
return true
|
||||
func KeyFromLabel(label string) (gocui.Key, bool) {
|
||||
if label == "" || label == "<disabled>" {
|
||||
return gocui.Key{}, true
|
||||
}
|
||||
|
||||
runeCount := utf8.RuneCountInString(label)
|
||||
if runeCount > 1 {
|
||||
_, ok := KeyByLabel[strings.ToLower(key)]
|
||||
return ok
|
||||
keyName, ok := KeyByLabel[strings.ToLower(label)]
|
||||
if !ok {
|
||||
return gocui.Key{}, false
|
||||
}
|
||||
return gocui.NewKeyName(keyName), true
|
||||
}
|
||||
|
||||
return true
|
||||
return gocui.NewKeyRune([]rune(label)[0]), true
|
||||
}
|
||||
|
||||
func isValidKeybindingKey(key string) bool {
|
||||
_, ok := KeyFromLabel(key)
|
||||
return ok
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,9 @@ package keybindings
|
|||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/gdamore/tcell/v3"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/constants"
|
||||
"github.com/jesseduffield/lazygit/pkg/gocui"
|
||||
)
|
||||
|
||||
|
|
@ -28,23 +25,11 @@ func LabelFromKey(key gocui.Key) string {
|
|||
return "unknown"
|
||||
}
|
||||
|
||||
func GetKey(key string) gocui.Key {
|
||||
if key == "<disabled>" {
|
||||
return gocui.Key{}
|
||||
func GetKey(label string) gocui.Key {
|
||||
key, ok := config.KeyFromLabel(label)
|
||||
if !ok {
|
||||
log.Fatalf("Unrecognized key %s, this should have been caught by user config validation", label)
|
||||
}
|
||||
|
||||
runeCount := utf8.RuneCountInString(key)
|
||||
if runeCount > 1 {
|
||||
keyName, ok := config.KeyByLabel[strings.ToLower(key)]
|
||||
if !ok {
|
||||
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
|
||||
}
|
||||
return gocui.NewKeyName(keyName)
|
||||
}
|
||||
|
||||
if runeCount == 1 {
|
||||
return gocui.NewKeyRune([]rune(key)[0])
|
||||
}
|
||||
|
||||
return gocui.Key{}
|
||||
return key
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue