diff options
author | Vitaly Ovchinnikov <v@ovch.ru> | 2024-04-02 09:47:58 +0000 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-04-13 21:47:32 +0200 |
commit | bd489a1c9017d1d8ac6aecff98f98939007273cd (patch) | |
tree | 7476cdac63c690e1364dba2c58ffac98b38607af /config | |
parent | a67fd7cb544b065b766fde65df7011f9190dcf39 (diff) | |
download | aerc-bd489a1c9017d1d8ac6aecff98f98939007273cd.tar.gz |
binds: fix FormatKeyStrokes to properly display certain keystrokes
Fix FormatKeyStrokes so it properly displays the strokes that are not
directly listed in `keyNames`, like ctrl+left, ctrl+pgup etc.
Add a test to check that the strokes are now formatted.
Signed-off-by: Vitaly Ovchinnikov <v@ovch.ru>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r-- | config/binds.go | 2 | ||||
-rw-r--r-- | config/binds_test.go | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/config/binds.go b/config/binds.go index 3ddc2578..1d391af7 100644 --- a/config/binds.go +++ b/config/binds.go @@ -473,7 +473,7 @@ func FormatKeyStrokes(keystrokes []KeyStroke) string { for _, stroke := range keystrokes { s := "" for name, ks := range keyNames { - if ks.Modifiers == stroke.Modifiers && ks.Key == stroke.Key { + if (ks.Modifiers == stroke.Modifiers || ks.Modifiers == vaxis.ModifierMask(0)) && ks.Key == stroke.Key { switch name { case "cr": s = "<enter>" diff --git a/config/binds_test.go b/config/binds_test.go index 7d4cd779..7325252d 100644 --- a/config/binds_test.go +++ b/config/binds_test.go @@ -85,3 +85,17 @@ func TestGetBinding(t *testing.T) { {vaxis.ModShift, vaxis.KeyUp}, }, BINDING_FOUND, ":open") } + +func TestKeyStrokeFormatting(t *testing.T) { + tests := []struct { + stroke KeyStroke + formatted string + }{ + {KeyStroke{vaxis.ModifierMask(0), vaxis.KeyLeft}, "<left>"}, + {KeyStroke{vaxis.ModCtrl, vaxis.KeyLeft}, "c-<left>"}, + } + + for _, test := range tests { + assert.Equal(t, test.formatted, FormatKeyStrokes([]KeyStroke{test.stroke})) + } +} |