diff --git a/docs/changelog.rst b/docs/changelog.rst index 065afb1f3..175aa73b5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -40,6 +40,8 @@ Detailed list of changes - Fix a regression in the previous release that broke the remote file kitten (:iss:`6186`) +- Fix a regression in the previous release that broke handling of some key board shortcuts in some kittens on some keyboard layouts (:iss:`6189`) + 0.28.0 [2023-04-15] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tools/tui/loop/key-encoding.go b/tools/tui/loop/key-encoding.go index 6aaef9e61..a7be0c916 100644 --- a/tools/tui/loop/key-encoding.go +++ b/tools/tui/loop/key-encoding.go @@ -140,26 +140,30 @@ func KeyEventFromCSI(csi string) *KeyEvent { csi = csi[:len(csi)-1] sections := strings.Split(csi, ";") - get_sub_sections := func(section string) []int { + get_sub_sections := func(section string, missing int) []int { p := strings.Split(section, ":") ans := make([]int, len(p)) for i, x := range p { - q, err := strconv.Atoi(x) - if err != nil { - return nil + if x == "" { + ans[i] = missing + } else { + q, err := strconv.Atoi(x) + if err != nil { + return nil + } + ans[i] = q } - ans[i] = q } return ans } - first_section := get_sub_sections(sections[0]) - second_section := make([]int, 0) - third_section := make([]int, 0) + first_section := get_sub_sections(sections[0], 0) + second_section := []int{} + third_section := []int{} if len(sections) > 1 { - second_section = get_sub_sections(sections[1]) + second_section = get_sub_sections(sections[1], 1) } if len(sections) > 2 { - third_section = get_sub_sections(sections[2]) + third_section = get_sub_sections(sections[2], 0) } var ans = KeyEvent{Type: PRESS} var keynum int diff --git a/tools/tui/loop/key-encoding_test.go b/tools/tui/loop/key-encoding_test.go new file mode 100644 index 000000000..1bcb87493 --- /dev/null +++ b/tools/tui/loop/key-encoding_test.go @@ -0,0 +1,30 @@ +// License: GPLv3 Copyright: 2023, Kovid Goyal, + +package loop + +import ( + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" +) + +var _ = fmt.Print + +func TestKeyEventFromCSI(t *testing.T) { + + test_text := func(csi string, expected, alternate string) { + ev := KeyEventFromCSI(csi) + if ev == nil { + t.Fatalf("Failed to get parse %#v", csi) + } + if diff := cmp.Diff(expected, ev.Text); diff != "" { + t.Fatalf("Failed to get text from %#v:\n%s", csi, diff) + } + if diff := cmp.Diff(alternate, ev.AlternateKey); diff != "" { + t.Fatalf("Failed to get alternate from %#v:\n%s", csi, diff) + } + } + test_text("121;;121u", "y", "") + test_text("121::122;;121u", "y", "z") +}