fix(config): resolve enter key submission and keybinding issues (#89)
closes #88 closes #85
This commit is contained in:
@@ -272,3 +272,29 @@ func TestMigration(t *testing.T) {
|
||||
t.Errorf("expected backup file update_state.json.bak to exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
input []byte
|
||||
expected string
|
||||
matched bool
|
||||
consumed int
|
||||
}{
|
||||
{[]byte{0x19}, "ctrl+y", true, 1},
|
||||
{[]byte{0x0b}, "ctrl+k", true, 1},
|
||||
{[]byte{0x0a}, "ctrl+j", true, 1},
|
||||
{[]byte{0x12}, "ctrl+r", true, 1},
|
||||
{[]byte{'j'}, "j", true, 1},
|
||||
{[]byte{'k'}, "k", true, 1},
|
||||
{[]byte{0x09}, "tab", true, 1},
|
||||
{[]byte{0x0d}, "enter", true, 1},
|
||||
{[]byte{0x0d}, "ctrl+r", false, 0},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
m, c := MatchKey(tt.input, tt.expected)
|
||||
if m != tt.matched || c != tt.consumed {
|
||||
t.Errorf("MatchKey(%v, %q) = (%v, %d); want (%v, %d)", tt.input, tt.expected, m, c, tt.matched, tt.consumed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,15 @@ func MatchKey(input []byte, expected string) (matched bool, consumed int) {
|
||||
expected = strings.ToLower(strings.TrimSpace(expected))
|
||||
expected = strings.TrimPrefix(expected, "<")
|
||||
expected = strings.TrimSuffix(expected, ">")
|
||||
expected = strings.ReplaceAll(expected, "-", "+")
|
||||
expected = strings.ReplaceAll(expected, "ctrk", "ctrl")
|
||||
expected = strings.ReplaceAll(expected, "ctl", "ctrl")
|
||||
|
||||
if len(expected) == 1 {
|
||||
if input[0] == expected[0] {
|
||||
return true, 1
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(expected, "ctrl+") && len(expected) == 6 {
|
||||
char := expected[5]
|
||||
|
||||
Reference in New Issue
Block a user