feat(tracker/gioui): user-defined keybindings.yml override defaults

The behaviour of the user-defined keybindings.yml was changed.
It now documents just the changes from the default keybindings.
An empty line with no action means "unbind the key".
This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-10-28 10:00:10 +02:00
parent eb9413b9a0
commit daf7fb1519
2 changed files with 22 additions and 6 deletions

View File

@ -1,3 +1,11 @@
# You can place your custom keybindings.yml in the Sointu config directory e.g.
# AppData\Roaming\sointu\keybindings.yml on Windows. There, you can override the
# default keybindings with your own. The format is the same as below. A
# keybinding without any action means unbinding the key. For example, the line
#
# - {key: "A"}
#
# will stop the A key from sending NoteOff events.
- {key: "C", shortcut: true, action: "Copy"}
- {key: "V", shortcut: true, action: "Paste"}
- {key: "A", shortcut: true, action: "SelectAll"}

View File

@ -60,10 +60,9 @@ func loadDefaultKeyBindings() []KeyBinding {
}
func init() {
keyBindings := loadCustomKeyBindings()
if keyBindings == nil {
keyBindings = loadDefaultKeyBindings()
}
keyBindings := loadDefaultKeyBindings()
keyBindings = append(keyBindings, loadCustomKeyBindings()...)
for _, kb := range keyBindings {
var mods key.Modifiers
if kb.Shortcut {
@ -84,8 +83,17 @@ func init() {
if kb.Super {
mods |= key.ModSuper
}
keyBindingMap[key.Event{Name: key.Name(kb.Key), Modifiers: mods, State: key.Press}] = kb.Action
if _, ok := keyActionMap[KeyAction(kb.Action)]; !ok {
keyEvent := key.Event{Name: key.Name(kb.Key), Modifiers: mods, State: key.Press}
action, ok := keyBindingMap[keyEvent] // if this key has been previously bound, remove it from the hint map
if ok {
delete(keyActionMap, KeyAction(action))
}
if kb.Action == "" { // unbind
delete(keyBindingMap, keyEvent)
} else { // bind
keyBindingMap[keyEvent] = kb.Action
// last binding of the some action wins for displaying the hint
modString := strings.Replace(mods.String(), "-", "+", -1)
text := kb.Key
if modString != "" {