mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
input: Kitty alternate should be reported even if no shifted text (#1817)
Reproduction: HU layout Ctrl+ő On release, we were previously not sending an alt text (we were sending it properly on press). Kitty sends it also on release and the spec makes it clear we should send it on release. This was just due to some faulty logic; added a test and fixed that.
This commit is contained in:

committed by
GitHub

parent
14417d2592
commit
1551c27578
@ -178,16 +178,16 @@ fn kitty(
|
||||
const view = try std.unicode.Utf8View.init(self.event.utf8);
|
||||
var it = view.iterator();
|
||||
|
||||
// We break early if there are codepoints...there are no alt keys.
|
||||
const cp1 = it.nextCodepoint() orelse break :alternates;
|
||||
// If we have a codepoint in our UTF-8 sequence, then we can
|
||||
// report the shifted version.
|
||||
if (it.nextCodepoint()) |cp1| {
|
||||
// Set the first alternate (shifted version)
|
||||
if (cp1 != seq.key and seq.mods.shift) seq.alternates[0] = cp1;
|
||||
|
||||
// We want to know if there are additional codepoints because
|
||||
// our logic below depends on the utf8 being a single codepoint.
|
||||
const has_cp2 = it.nextCodepoint() != null;
|
||||
|
||||
// Set the first alternate (shifted version)
|
||||
if (cp1 != seq.key and seq.mods.shift) seq.alternates[0] = cp1;
|
||||
|
||||
// Set the base layout key. We only report this if this codepoint
|
||||
// differs from our pressed key.
|
||||
if (self.event.key.codepoint()) |base| {
|
||||
@ -197,6 +197,13 @@ fn kitty(
|
||||
seq.alternates[1] = base;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No UTF-8 so we can't report a shifted key but we can still
|
||||
// report a base layout key.
|
||||
if (self.event.key.codepoint()) |base| {
|
||||
if (base != seq.key) seq.alternates[1] = base;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self.kitty_flags.report_associated and seq.event != .release) associated: {
|
||||
@ -1387,6 +1394,29 @@ test "kitty: report alternates with ru layout caps lock" {
|
||||
try testing.expectEqualStrings("\x1b[1095::59;65;1063u", actual);
|
||||
}
|
||||
|
||||
test "kitty: report alternates with hu layout release" {
|
||||
var buf: [128]u8 = undefined;
|
||||
var enc: KeyEncoder = .{
|
||||
.event = .{
|
||||
.action = .release,
|
||||
.key = .left_bracket,
|
||||
.mods = .{ .ctrl = true },
|
||||
.utf8 = "",
|
||||
.unshifted_codepoint = 337,
|
||||
},
|
||||
.kitty_flags = .{
|
||||
.disambiguate = true,
|
||||
.report_all = true,
|
||||
.report_alternates = true,
|
||||
.report_associated = true,
|
||||
.report_events = true,
|
||||
},
|
||||
};
|
||||
|
||||
const actual = try enc.kitty(&buf);
|
||||
try testing.expectEqualStrings("[337::91;5:3u", actual[1..]);
|
||||
}
|
||||
|
||||
// macOS generates utf8 text for arrow keys.
|
||||
test "kitty: up arrow with utf8" {
|
||||
var buf: [128]u8 = undefined;
|
||||
|
Reference in New Issue
Block a user