From daf7fb1519856a0ab279815f19d4907bf48902e3 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:00:10 +0200 Subject: [PATCH] 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". --- tracker/gioui/keybindings.yml | 8 ++++++++ tracker/gioui/keyevent.go | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tracker/gioui/keybindings.yml b/tracker/gioui/keybindings.yml index 2570151..fd54a97 100644 --- a/tracker/gioui/keybindings.yml +++ b/tracker/gioui/keybindings.yml @@ -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"} diff --git a/tracker/gioui/keyevent.go b/tracker/gioui/keyevent.go index 3ae19d5..b7e2f96 100644 --- a/tracker/gioui/keyevent.go +++ b/tracker/gioui/keyevent.go @@ -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 != "" {