feat: cache command IDs when executing keybindings

This commit is contained in:
CJ van den Berg 2024-11-18 19:29:23 +01:00
parent 92b3b93a1c
commit 22fdff4543
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -98,6 +98,7 @@ const Binding = struct {
keys: []KeyEvent, keys: []KeyEvent,
command: []const u8, command: []const u8,
args: []const u8, args: []const u8,
command_id: ?command.ID = null,
fn deinit(self: *const @This(), allocator: std.mem.Allocator) void { fn deinit(self: *const @This(), allocator: std.mem.Allocator) void {
allocator.free(self.keys); allocator.free(self.keys);
@ -109,8 +110,12 @@ const Binding = struct {
return self.keys.items.len; return self.keys.items.len;
} }
fn execute(self: @This()) !void { fn execute(self: *@This()) !void {
try command.executeName(self.command, .{ .args = .{ .buf = self.args } }); 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 }; const MatchResult = enum { match_impossible, match_possible, matched };