input: parse binds containing equal signs correctly (#7544)

Since the W3C rewrite we're able to specify codepoints like `+` directly
in the config format who otherwise have special meanings. Turns out we
forgot to do the same for `=`.
pull/7545/head
Mitchell Hashimoto 2025-06-07 16:30:01 -07:00 committed by GitHub
commit e986beb6a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 2 deletions

View File

@ -63,9 +63,11 @@ pub const Parser = struct {
const flags, const start_idx = try parseFlags(raw_input); const flags, const start_idx = try parseFlags(raw_input);
const input = raw_input[start_idx..]; const input = raw_input[start_idx..];
// Find the first = which splits are mapping into the trigger // Find the last = which splits are mapping into the trigger
// and action, respectively. // and action, respectively.
const eql_idx = std.mem.indexOf(u8, input, "=") orelse return Error.InvalidFormat; // We use the last = because the keybind itself could contain
// raw equal signs (for the = codepoint)
const eql_idx = std.mem.lastIndexOf(u8, input, "=") orelse return Error.InvalidFormat;
// Sequence iterator goes up to the equal, action is after. We can // Sequence iterator goes up to the equal, action is after. We can
// parse the action now. // parse the action now.
@ -2191,6 +2193,32 @@ test "parse: plus sign" {
try testing.expectError(Error.InvalidFormat, parseSingle("++=ignore")); try testing.expectError(Error.InvalidFormat, parseSingle("++=ignore"));
} }
test "parse: equals sign" {
const testing = std.testing;
try testing.expectEqual(
Binding{
.trigger = .{ .key = .{ .unicode = '=' } },
.action = .ignore,
},
try parseSingle("==ignore"),
);
// Modifier
try testing.expectEqual(
Binding{
.trigger = .{
.key = .{ .unicode = '=' },
.mods = .{ .ctrl = true },
},
.action = .ignore,
},
try parseSingle("ctrl+==ignore"),
);
try testing.expectError(Error.InvalidFormat, parseSingle("=ignore"));
}
// For Ghostty 1.2+ we changed our key names to match the W3C and removed // For Ghostty 1.2+ we changed our key names to match the W3C and removed
// `physical:`. This tests the backwards compatibility with the old format. // `physical:`. This tests the backwards compatibility with the old format.
// Note that our backwards compatibility isn't 100% perfect since triggers // Note that our backwards compatibility isn't 100% perfect since triggers