diff --git a/src/command.zig b/src/command.zig index a8d5c27..0f8d36c 100644 --- a/src/command.zig +++ b/src/command.zig @@ -118,7 +118,7 @@ pub fn execute(id: ID, ctx: Context) tp.result { } } -pub fn getId(name: []const u8) ?ID { +pub fn get_id(name: []const u8) ?ID { for (commands.items) |cmd| { if (cmd) |p| if (std.mem.eql(u8, p.name, name)) @@ -127,6 +127,11 @@ pub fn getId(name: []const u8) ?ID { return null; } +pub fn get_name(id: ID) ?[]const u8 { + if (id >= commands.items.len) return null; + return (commands.items[id] orelse return null).name; +} + pub fn get_id_cache(name: []const u8, id: *?ID) ?ID { for (commands.items) |cmd| { if (cmd) |p| @@ -145,7 +150,7 @@ const suppressed_errors = .{ }; pub fn executeName(name: []const u8, ctx: Context) tp.result { - const id = getId(name); + const id = get_id(name); if (id) |id_| return execute(id_, ctx); inline for (suppressed_errors) |err| if (std.mem.eql(u8, err, name)) return; return tp.exit_fmt("CommandNotFound: {s}", .{name}); diff --git a/src/tui/editor.zig b/src/tui/editor.zig index aedb04b..8ea49a6 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -3592,7 +3592,7 @@ pub const Editor = struct { pub fn goto_next_diagnostic(self: *Self, _: Context) Result { if (self.diagnostics.items.len == 0) { - if (command.getId("goto_next_file")) |id| + if (command.get_id("goto_next_file")) |id| return command.execute(id, .{}); return; } @@ -3608,7 +3608,7 @@ pub const Editor = struct { pub fn goto_prev_diagnostic(self: *Self, _: Context) Result { if (self.diagnostics.items.len == 0) { - if (command.getId("goto_prev_file")) |id| + if (command.get_id("goto_prev_file")) |id| return command.execute(id, .{}); return; } diff --git a/src/tui/mode/overlay/command_palette.zig b/src/tui/mode/overlay/command_palette.zig index 2eb6978..3eb0c2c 100644 --- a/src/tui/mode/overlay/command_palette.zig +++ b/src/tui/mode/overlay/command_palette.zig @@ -120,7 +120,7 @@ pub fn restore_state(palette: *Type) !void { error.TooShort => return, else => return e, }) { - const id = command.getId(name_) orelse continue; + const id = command.get_id(name_) orelse continue; set_used_time(palette, id, used_time); } }