From 22fdff4543594d606bbfde6115bf5b30362f6af9 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 18 Nov 2024 19:29:23 +0100 Subject: [PATCH] feat: cache command IDs when executing keybindings --- src/keybind/dynamic/keybind.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/keybind/dynamic/keybind.zig b/src/keybind/dynamic/keybind.zig index 9cdc0c7..ba85245 100644 --- a/src/keybind/dynamic/keybind.zig +++ b/src/keybind/dynamic/keybind.zig @@ -98,6 +98,7 @@ const Binding = struct { keys: []KeyEvent, command: []const u8, args: []const u8, + command_id: ?command.ID = null, fn deinit(self: *const @This(), allocator: std.mem.Allocator) void { allocator.free(self.keys); @@ -109,8 +110,12 @@ const Binding = struct { return self.keys.items.len; } - fn execute(self: @This()) !void { - try command.executeName(self.command, .{ .args = .{ .buf = self.args } }); + fn execute(self: *@This()) !void { + const id = self.command_id orelse + command.get_id_cache(self.command, &self.command_id) orelse { + return tp.exit_error(error.InputTargetNotFound, null); + }; + try command.execute(id, .{ .args = .{ .buf = self.args } }); } const MatchResult = enum { match_impossible, match_possible, matched };