mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
input: parse triggers with codepoints that map to keys as translated
Fixes #4146 This makes it so that keys such as `cmd+1` and `cmd+one` are identical.
This commit is contained in:

committed by
Jonathan Lopez

parent
e9d54e97e0
commit
4a231d6aa5
@ -4746,9 +4746,11 @@ pub const Keybinds = struct {
|
||||
try list.parseCLI(alloc, "ctrl+z>2=goto_tab:2");
|
||||
try list.formatEntry(formatterpkg.entryFormatter("keybind", buf.writer()));
|
||||
|
||||
// Note they turn into translated keys because they match
|
||||
// their ASCII mapping.
|
||||
const want =
|
||||
\\keybind = ctrl+z>1=goto_tab:1
|
||||
\\keybind = ctrl+z>2=goto_tab:2
|
||||
\\keybind = ctrl+z>two=goto_tab:2
|
||||
\\keybind = ctrl+z>one=goto_tab:1
|
||||
\\
|
||||
;
|
||||
try std.testing.expectEqualStrings(want, buf.items);
|
||||
|
@ -1019,6 +1019,14 @@ pub const Trigger = struct {
|
||||
const cp = it.nextCodepoint() orelse break :unicode;
|
||||
if (it.nextCodepoint() != null) break :unicode;
|
||||
|
||||
// If this is ASCII and we have a translated key, set that.
|
||||
if (std.math.cast(u8, cp)) |ascii| {
|
||||
if (key.Key.fromASCII(ascii)) |k| {
|
||||
result.key = .{ .translated = k };
|
||||
continue :loop;
|
||||
}
|
||||
}
|
||||
|
||||
result.key = .{ .unicode = cp };
|
||||
continue :loop;
|
||||
}
|
||||
@ -1554,6 +1562,19 @@ test "parse: triggers" {
|
||||
try parseSingle("a=ignore"),
|
||||
);
|
||||
|
||||
// unicode keys that map to translated
|
||||
try testing.expectEqual(Binding{
|
||||
.trigger = .{ .key = .{ .translated = .one } },
|
||||
.action = .{ .ignore = {} },
|
||||
}, try parseSingle("1=ignore"));
|
||||
try testing.expectEqual(Binding{
|
||||
.trigger = .{
|
||||
.mods = .{ .super = true },
|
||||
.key = .{ .translated = .period },
|
||||
},
|
||||
.action = .{ .ignore = {} },
|
||||
}, try parseSingle("cmd+.=ignore"));
|
||||
|
||||
// single modifier
|
||||
try testing.expectEqual(Binding{
|
||||
.trigger = .{
|
||||
|
@ -729,7 +729,9 @@ pub const Key = enum(c_int) {
|
||||
.{ '\t', .tab },
|
||||
|
||||
// Keypad entries. We just assume keypad with the kp_ prefix
|
||||
// so that has some special meaning. These must also always be last.
|
||||
// so that has some special meaning. These must also always be last,
|
||||
// so that our `fromASCII` function doesn't accidentally map them
|
||||
// over normal numerics and other keys.
|
||||
.{ '0', .kp_0 },
|
||||
.{ '1', .kp_1 },
|
||||
.{ '2', .kp_2 },
|
||||
|
Reference in New Issue
Block a user