Kitty key encoding should not encode backspace if UTF-8 text is present

This applies the same logic from #1659 to Kitty encoding.
pull/5728/head
Serim Son 2025-02-13 13:38:18 +09:00 committed by Mitchell Hashimoto
parent 9c064216a2
commit d61e53d6d6
1 changed files with 29 additions and 5 deletions

View File

@ -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 = .{