From bd489a1c9017d1d8ac6aecff98f98939007273cd Mon Sep 17 00:00:00 2001 From: Vitaly Ovchinnikov Date: Tue, 2 Apr 2024 09:47:58 +0000 Subject: 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 Acked-by: Robin Jarry --- config/binds.go | 2 +- config/binds_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 = "" 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}, ""}, + {KeyStroke{vaxis.ModCtrl, vaxis.KeyLeft}, "c-"}, + } + + for _, test := range tests { + assert.Equal(t, test.formatted, FormatKeyStrokes([]KeyStroke{test.stroke})) + } +} -- cgit v1.2.3-54-g00ecf