input: global/all bindings can't be sequenced

This commit is contained in:
Mitchell Hashimoto
2024-09-23 14:12:29 -07:00
parent 66143a33ef
commit 070cc22172
2 changed files with 18 additions and 2 deletions

View File

@ -704,6 +704,9 @@ class: ?[:0]const u8 = null,
/// `ctrl+a>t`, and then bind `ctrl+a` directly, both `ctrl+a>n` and /// `ctrl+a>t`, and then bind `ctrl+a` directly, both `ctrl+a>n` and
/// `ctrl+a>t` will become unbound. /// `ctrl+a>t` will become unbound.
/// ///
/// * Trigger sequences are not allowed for `global:` or `all:`-prefixed
/// triggers. This is a limitation we could remove in the future.
///
/// Action is the action to take when the trigger is satisfied. It takes the /// Action is the action to take when the trigger is satisfied. It takes the
/// format `action` or `action:param`. The latter form is only valid if the /// format `action` or `action:param`. The latter form is only valid if the
/// action requires a parameter. /// action requires a parameter.
@ -762,7 +765,10 @@ class: ?[:0]const u8 = null,
/// any) will not be sent to the running program in the terminal. If /// any) will not be sent to the running program in the terminal. If
/// you wish to send the encoded value to the program, specify the /// you wish to send the encoded value to the program, specify the
/// `unconsumed:` prefix before the entire keybind. For example: /// `unconsumed:` prefix before the entire keybind. For example:
/// `unconsumed:ctrl+a=reload_config` /// `unconsumed:ctrl+a=reload_config`. `global:` and `all:`-prefixed
/// keybinds will always consume the input regardless of this setting.
/// Since they are not associated with a specific terminal surface,
/// they're never encoded.
/// ///
/// Multiple prefixes can be specified. For example, /// Multiple prefixes can be specified. For example,
/// `global:unconsumed:ctrl+a=reload_config` will make the keybind global /// `global:unconsumed:ctrl+a=reload_config` will make the keybind global

View File

@ -109,7 +109,11 @@ pub const Parser = struct {
const trigger = (try self.trigger_it.next()) orelse return null; const trigger = (try self.trigger_it.next()) orelse return null;
// If this is our last trigger then it is our final binding. // If this is our last trigger then it is our final binding.
if (!self.trigger_it.done()) return .{ .leader = trigger }; if (!self.trigger_it.done()) {
// Global/all bindings can't be sequences
if (self.flags.global or self.flags.all) return error.InvalidFormat;
return .{ .leader = trigger };
}
// Out of triggers, yield the final action. // Out of triggers, yield the final action.
return .{ .binding = .{ return .{ .binding = .{
@ -1342,6 +1346,12 @@ test "parse: global triggers" {
.consumed = false, .consumed = false,
}, },
}, try parseSingle("unconsumed:global:a+shift=ignore")); }, try parseSingle("unconsumed:global:a+shift=ignore"));
// global sequences not allowed
{
var p = try Parser.init("global:a>b=ignore");
try testing.expectError(Error.InvalidFormat, p.next());
}
} }
test "parse: modifier aliases" { test "parse: modifier aliases" {