mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-05 03:14:14 +00:00
input: activate/deactivate key table binding actions
This commit is contained in:
@@ -5569,6 +5569,49 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
||||
{},
|
||||
),
|
||||
|
||||
inline .activate_key_table,
|
||||
.activate_key_table_once,
|
||||
=> |name, tag| {
|
||||
// Look up the table in our config
|
||||
const set = self.config.keybind.tables.getPtr(name) orelse
|
||||
return false;
|
||||
|
||||
// If this is the same table as is currently active, then
|
||||
// do nothing.
|
||||
if (self.keyboard.table_stack.items.len > 0) {
|
||||
const items = self.keyboard.table_stack.items;
|
||||
const active = items[items.len - 1];
|
||||
if (active == set) return false;
|
||||
}
|
||||
|
||||
// Add the table to the stack.
|
||||
try self.keyboard.table_stack.append(self.alloc, set);
|
||||
|
||||
// TODO: once
|
||||
_ = tag;
|
||||
},
|
||||
|
||||
.deactivate_key_table => switch (self.keyboard.table_stack.items.len) {
|
||||
// No key table active. This does nothing.
|
||||
0 => return false,
|
||||
|
||||
// Final key table active, clear our state.
|
||||
1 => self.keyboard.table_stack.clearAndFree(self.alloc),
|
||||
|
||||
// Restore the prior key table. We don't free any memory in
|
||||
// this case because we assume it will be freed later when
|
||||
// we finish our key table.
|
||||
else => _ = self.keyboard.table_stack.pop(),
|
||||
},
|
||||
|
||||
.deactivate_all_key_tables => switch (self.keyboard.table_stack.items.len) {
|
||||
// No key table active. This does nothing.
|
||||
0 => return false,
|
||||
|
||||
// Clear the entire table stack.
|
||||
else => self.keyboard.table_stack.clearAndFree(self.alloc),
|
||||
},
|
||||
|
||||
.crash => |location| switch (location) {
|
||||
.main => @panic("crash binding action, crashing intentionally"),
|
||||
|
||||
|
||||
@@ -799,6 +799,32 @@ pub const Action = union(enum) {
|
||||
/// be undone or redone.
|
||||
redo,
|
||||
|
||||
/// 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
|
||||
/// `activate_key_table_once` action instead.
|
||||
///
|
||||
/// If the named key table does not exist, this action has no effect
|
||||
/// and performable will report false.
|
||||
///
|
||||
/// If the named key table is already the currently active key table,
|
||||
/// this action has no effect and performable will report false.
|
||||
activate_key_table: []const u8,
|
||||
|
||||
/// Same as activate_key_table, but the key table will only be active
|
||||
/// until the first valid keybinding from that table is used (including
|
||||
/// any defined `catch_all` bindings).
|
||||
activate_key_table_once: []const u8,
|
||||
|
||||
/// Deactivate the currently active key table, if any. The next most
|
||||
/// recently activated key table (if any) will become active again.
|
||||
/// If no key table is active, this action has no effect.
|
||||
deactivate_key_table,
|
||||
|
||||
/// Deactivate all active key tables. If no active key table exists,
|
||||
/// this will report performable as false.
|
||||
deactivate_all_key_tables,
|
||||
|
||||
/// Quit Ghostty.
|
||||
quit,
|
||||
|
||||
@@ -1253,6 +1279,10 @@ pub const Action = union(enum) {
|
||||
.toggle_background_opacity,
|
||||
.show_on_screen_keyboard,
|
||||
.reset_window_size,
|
||||
.activate_key_table,
|
||||
.activate_key_table_once,
|
||||
.deactivate_key_table,
|
||||
.deactivate_all_key_tables,
|
||||
.crash,
|
||||
=> .surface,
|
||||
|
||||
|
||||
@@ -671,6 +671,10 @@ fn actionCommands(action: Action.Key) []const Command {
|
||||
.write_scrollback_file,
|
||||
.goto_tab,
|
||||
.resize_split,
|
||||
.activate_key_table,
|
||||
.activate_key_table_once,
|
||||
.deactivate_key_table,
|
||||
.deactivate_all_key_tables,
|
||||
.crash,
|
||||
=> comptime &.{},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user