diff --git a/src/config/Config.zig b/src/config/Config.zig index eb3d28d95..7d9c7d8cc 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -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); diff --git a/src/input/Binding.zig b/src/input/Binding.zig index 85721339d..b2c03b674 100644 --- a/src/input/Binding.zig +++ b/src/input/Binding.zig @@ -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 = .{ diff --git a/src/input/key.zig b/src/input/key.zig index eb2526593..a875611d0 100644 --- a/src/input/key.zig +++ b/src/input/key.zig @@ -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 },