input: add end_key_sequence binding action (#10098)

End the currently active key sequence, if any, and flush the keys up to
this point to the terminal, excluding the key that triggered this
action.

For example: `ctrl+w>escape=end_key_sequence` would encode `ctrl+w` to
the terminal and exit the key sequence. Or, more fancy,
`ctrl+w>catch_all=end_key_sequence` would exit the sequence without
encoding whatever key was invalid!

Normally, an invalid sequence will reset the key sequence and flush all
data including the invalid key. This action allows you to flush only the
prior keys, which is useful when you want to bind something like a
control key (`ctrl+w`) but not send additional inputs.
This commit is contained in:
Mitchell Hashimoto
2025-12-29 12:12:16 -08:00
committed by GitHub
3 changed files with 24 additions and 0 deletions

View File

@@ -5794,6 +5794,14 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
return try self.deactivateAllKeyTables();
},
.end_key_sequence => {
// End the key sequence and flush queued keys to the terminal,
// but don't encode the key that triggered this action. This
// will do that because leaf keys (keys with bindings) aren't
// in the queued encoding list.
self.endKeySequence(.flush, .retain);
},
.crash => |location| switch (location) {
.main => @panic("crash binding action, crashing intentionally"),

View File

@@ -827,6 +827,20 @@ pub const Action = union(enum) {
/// be undone or redone.
redo,
/// End the currently active key sequence, if any, and flush the
/// keys up to this point to the terminal, excluding the key that
/// triggered this action.
///
/// For example: `ctrl+w>escape=end_key_sequence` would encode
/// `ctrl+w` to the terminal and exit the key sequence.
///
/// Normally, an invalid sequence will reset the key sequence and
/// flush all data including the invalid key. This action allows
/// you to flush only the prior keys, which is useful when you want
/// to bind something like a control key (`ctrl+w`) but not send
/// additional inputs.
end_key_sequence,
/// Activate a named key table (see `keybind` configuration documentation).
/// The named key table will remain active until `deactivate_key_table`
/// is called. If you want a one-shot key table activation, use the
@@ -1316,6 +1330,7 @@ pub const Action = union(enum) {
.activate_key_table_once,
.deactivate_key_table,
.deactivate_all_key_tables,
.end_key_sequence,
.crash,
=> .surface,

View File

@@ -696,6 +696,7 @@ fn actionCommands(action: Action.Key) []const Command {
.activate_key_table_once,
.deactivate_key_table,
.deactivate_all_key_tables,
.end_key_sequence,
.crash,
=> comptime &.{},