diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 5dd92b8..92c734a 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -1951,9 +1951,12 @@ pub const Editor = struct { self.match_done_token = self.match_token; } - pub fn clear_matches_if_type(self: *Self, match_type: Match.Type) void { - if (self.match_type == match_type) + pub fn clear_matches_if_type(self: *Self, match_type: Match.Type) bool { + if (self.match_type == match_type) { self.clear_matches(); + return true; + } + return false; } pub fn sort_matches(self: *Self) void { diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index d822bde..111b53c 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -1445,8 +1445,8 @@ fn location_jump(from: tp.pid_ref, file_path: []const u8, cursor: location_histo } fn clear_auto_find(self: *Self, editor: *ed.Editor) void { - editor.clear_matches_if_type(.auto_find); - self.store_last_match_text(null); + if (editor.clear_matches_if_type(.auto_find)) + self.store_last_match_text(null); } fn is_last_match_text(self: *Self, text: []const u8) bool { diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index 89d1866..8c00db7 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -27,7 +27,6 @@ pub fn Create(options: type) type { allocator: std.mem.Allocator, modal: *ModalBackground.State(*Self), menu: *Menu.State(*Self), - mode: keybind.Mode, inputbox: *InputBox.State(*Self), logger: log.Logger, longest: usize = 0, @@ -84,20 +83,13 @@ pub fn Create(options: type) type { }))).dynamic_cast(InputBox.State(*Self)) orelse unreachable, .view_rows = get_view_rows(tui.screen()), .entries = .empty, - .mode = try keybind.mode("overlay/palette", allocator, .{ - .insert_command = "overlay_insert_bytes", - }), }; try self.commands.init(self); - self.mode.event_handler = EventHandler.to_owned(self); - self.mode.name = options.name; if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style; self.longest_hint = if (@hasDecl(options, "load_entries_with_args")) try options.load_entries_with_args(self, ctx) else try options.load_entries(self); - if (self.entries.items.len > 0) - self.initial_selected = self.menu.selected; if (@hasDecl(options, "restore_state")) options.restore_state(self) catch {}; if (@hasDecl(options, "initial_query")) blk: { @@ -109,7 +101,12 @@ pub fn Create(options: type) type { try self.start_query(0); try mv.floating_views.add(self.modal.widget()); try mv.floating_views.add(self.menu.container_widget); - return self.mode; + var mode = try keybind.mode("overlay/palette", allocator, .{ + .insert_command = "overlay_insert_bytes", + }); + mode.event_handler = EventHandler.to_owned(self); + mode.name = options.name; + return mode; } pub fn deinit(self: *Self) void { diff --git a/src/tui/mode/overlay/task_palette.zig b/src/tui/mode/overlay/task_palette.zig index 6dbaa1e..393f722 100644 --- a/src/tui/mode/overlay/task_palette.zig +++ b/src/tui/mode/overlay/task_palette.zig @@ -34,7 +34,7 @@ pub fn load_entries(palette: *Type) !usize { (try palette.entries.addOne(palette.allocator)).* = .{ .label = try palette.allocator.dupe(u8, task) }; longest = @max(longest, task.len); } - const hints = palette.mode.keybind_hints; + const hints = if (tui.input_mode()) |m| m.keybind_hints else @panic("no keybind hints"); var longest_hint: usize = 0; longest_hint = @max(longest_hint, try add_palette_command(palette, "add_task", hints)); longest_hint = @max(longest_hint, try add_palette_command(palette, "palette_menu_delete_item", hints));