From d61e53d6d66fce40c8ec501b7da46221016b5d47 Mon Sep 17 00:00:00 2001 From: Serim Son Date: Thu, 13 Feb 2025 13:38:18 +0900 Subject: [PATCH] Kitty key encoding should not encode backspace if UTF-8 text is present This applies the same logic from #1659 to Kitty encoding. --- src/input/KeyEncoder.zig | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/input/KeyEncoder.zig b/src/input/KeyEncoder.zig index 8be5c672c..4aaae25e9 100644 --- a/src/input/KeyEncoder.zig +++ b/src/input/KeyEncoder.zig @@ -101,11 +101,14 @@ fn kitty( // IME confirmation still sends an enter key so if we have enter // and UTF8 text we just send it directly since we assume that is - // whats happening. - if (self.event.key == .enter and - self.event.utf8.len > 0) - { - return try copyToBuf(buf, self.event.utf8); + // whats happening. See legacy()'s similar logic for more details + // on how to verify this. + if (self.event.utf8.len > 0) { + switch (self.event.key) { + .enter => return try copyToBuf(buf, self.event.utf8), + .backspace => return "", + else => {}, + } } // If we're reporting all then we always send CSI sequences. @@ -1723,6 +1726,27 @@ test "kitty: keypad number" { try testing.expectEqualStrings("[57400;;49u", actual[1..]); } +test "kitty: backspace with utf8 (dead key state)" { + var buf: [128]u8 = undefined; + var enc: KeyEncoder = .{ + .event = .{ + .key = .backspace, + .utf8 = "A", + .unshifted_codepoint = 0x0D, + }, + .kitty_flags = .{ + .disambiguate = true, + .report_events = true, + .report_alternates = true, + .report_all = true, + .report_associated = true, + }, + }; + + const actual = try enc.kitty(&buf); + try testing.expectEqualStrings("", actual); +} + test "legacy: backspace with utf8 (dead key state)" { var buf: [128]u8 = undefined; var enc: KeyEncoder = .{