From 1c2dd4c9f15ddc9cba0849c4077525bd6d64cd6a Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 3 Oct 2022 12:49:53 -0500 Subject: [PATCH] bindings: properly check for exKey keystrokes When checking for an exKey, aerc inspects the key and the rune of the event vs the exkey binding. Runes should only be inspected if the key is a tcell.KeyRune. Some Ctrl-[:alpha:] keys report a rune in tcell, but aerc does not have these bound to the keystroke definition. Only has a rune bound, and is one of the very few keys that can actually be bound to exKey Only compare the Rune field if the key is of type KeyRune. Otherwise, compare the Key. Also compare any modifiers with the keystroke/key event. These changes allow for any control or alt key combination to be bound to the exkey. Update documentaiton to reflect that the default keybind is ':', and not Fixes: https://todo.sr.ht/~rjarry/aerc/67 Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- doc/aerc-config.5.scd | 2 +- widgets/aerc.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index 8b7aa55..9eb8790 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -819,7 +819,7 @@ each binding context: This can be set to a keystroke which will bring up the command input in this context. - Default: + Default: ':' In addition to letters, special keys may be specified in . The following special keys are supported: diff --git a/widgets/aerc.go b/widgets/aerc.go index 7209b2d..bdd18dd 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -339,7 +339,7 @@ func (aerc *Aerc) Event(event tcell.Event) bool { // Keybindings still use : even if you change the ex key exKey = aerc.conf.Bindings.Global.ExKey } - if event.Key() == exKey.Key && event.Rune() == exKey.Rune { + if aerc.isExKey(event, exKey) { aerc.BeginExCommand("") return true } @@ -850,3 +850,11 @@ func errorScreen(s string, conf config.UIConfig) ui.Drawable { grid.AddChild(ui.NewFill(' ', tcell.StyleDefault)).At(2, 0) return grid } + +func (aerc *Aerc) isExKey(event *tcell.EventKey, exKey config.KeyStroke) bool { + if event.Key() == tcell.KeyRune { + // Compare runes if it's a KeyRune + return event.Modifiers() == exKey.Modifiers && event.Rune() == exKey.Rune + } + return event.Modifiers() == exKey.Modifiers && event.Key() == exKey.Key +}