diff --git a/src/config.zig b/src/config.zig index 51cbe70..e12bab1 100644 --- a/src/config.zig +++ b/src/config.zig @@ -71,7 +71,6 @@ centered_view_min_screen_width: usize = 145, lsp_output: enum { quiet, verbose } = .quiet, keybind_mode: KeybindMode = .normal, -dropdown_keybinds: DropdownKeybindMode = .standard, include_files: []const u8 = "", @@ -159,11 +158,6 @@ pub const KeybindMode = enum { ignore_alt_text_modifiers, }; -pub const DropdownKeybindMode = enum { - standard, - noninvasive, -}; - pub const InitialFindQuery = enum { empty, selection, diff --git a/src/keybind/builtin/flow.json b/src/keybind/builtin/flow.json index 081c8df..9c613cc 100644 --- a/src/keybind/builtin/flow.json +++ b/src/keybind/builtin/flow.json @@ -375,7 +375,7 @@ ["right_control", "palette_menu_activate_quick"] ] }, - "overlay/dropdown-noninvasive": { + "overlay/dropdown": { "inherit": "normal", "press": [ ["alt+f9", "dropdown_next_widget_style"], @@ -388,19 +388,6 @@ ["tab", "palette_menu_complete"] ] }, - "overlay/dropdown": { - "inherit": "normal", - "press": [ - ["alt+f9", "dropdown_next_widget_style"], - ["ctrl+p", "palette_menu_up"], - ["ctrl+n", "palette_menu_down"], - ["escape", "palette_menu_cancel"], - ["up", "palette_menu_up"], - ["down", "palette_menu_down"], - ["enter", "palette_menu_activate"], - ["tab", "palette_menu_complete"] - ] - }, "mini/numeric": { "press": [ ["ctrl+?", "toggle_keybind_hints"], diff --git a/src/tui/mode/overlay/completion_dropdown.zig b/src/tui/mode/overlay/completion_dropdown.zig index 9910fb9..1477348 100644 --- a/src/tui/mode/overlay/completion_dropdown.zig +++ b/src/tui/mode/overlay/completion_dropdown.zig @@ -30,7 +30,6 @@ pub const Entry = struct { pub const ValueType = struct { start: ed.CurSel = .{}, cursor: ed.Cursor = .{}, - view: ed.View = .{}, replace: ?Buffer.Selection = null, }; pub const defaultValue: ValueType = .{}; @@ -89,16 +88,14 @@ pub fn handle_event(self: *Type, _: tp.pid_ref, m: tp.message) tp.result { try m.match(.{ "E", "close" })) { const editor = tui.get_active_editor() orelse return; - if (!self.value.cursor.eql(editor.get_primary().cursor) or !self.value.view.eql(editor.view)) { - tp.self_pid().send(.{ "cmd", "palette_menu_cancel" }) catch |e| self.logger.err(module_name, e); - } + if (!self.value.cursor.eql(editor.get_primary().cursor)) + tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| self.logger.err(module_name, e); } } pub fn initial_query(self: *Type, allocator: std.mem.Allocator) error{OutOfMemory}![]const u8 { const editor = tui.get_active_editor() orelse return allocator.dupe(u8, ""); self.value.cursor = editor.get_primary().cursor; - self.value.view = editor.view; return if (self.value.replace) |replace| blk: { const sel: Buffer.Selection = .{ .begin = replace.begin, .end = self.value.start.cursor }; break :blk editor.get_selection(sel, allocator) catch break :blk allocator.dupe(u8, ""); @@ -298,8 +295,6 @@ pub fn updated(self: *Type, button_: ?*Type.ButtonType) !void { } try mv.set_info_content(" ", .append); // blank line try mv.set_info_content(values.documentation, .append); - if (mv.get_active_editor()) |editor| - self.value.view = editor.view; } pub fn cancel(_: *Type) !void { diff --git a/src/tui/mode/overlay/dropdown.zig b/src/tui/mode/overlay/dropdown.zig index a825e08..4a480db 100644 --- a/src/tui/mode/overlay/dropdown.zig +++ b/src/tui/mode/overlay/dropdown.zig @@ -29,6 +29,7 @@ pub const Placement = enum { pub fn Create(options: type) type { return struct { allocator: std.mem.Allocator, + modal: *ModalBackground.State(*Self), menu: *Menu.State(*Self), mode: keybind.Mode, query: std.ArrayList(u8), @@ -67,6 +68,17 @@ pub fn Create(options: type) type { errdefer allocator.destroy(self); self.* = .{ .allocator = allocator, + .modal = try ModalBackground.create(*Self, allocator, tui.mainview_widget(), .{ + .ctx = self, + .on_click = mouse_palette_menu_cancel, + .on_render = if (@hasDecl(options, "modal_dim")) + if (options.modal_dim) + ModalBackground.Options(*Self).on_render_dim + else + ModalBackground.Options(*Self).on_render_default + else + ModalBackground.Options(*Self).on_render_dim, + }), .menu = try Menu.create(*Self, allocator, tui.plane(), .{ .ctx = self, .style = widget_type, @@ -81,10 +93,7 @@ pub fn Create(options: type) type { .query = .empty, .view_rows = get_view_rows(tui.screen()), .entries = .empty, - .mode = try keybind.mode(switch (tui.config().dropdown_keybinds) { - .standard => "overlay/dropdown", - .noninvasive => "overlay/dropdown-noninvasive", - }, allocator, .{ + .mode = try keybind.mode("overlay/dropdown", allocator, .{ .insert_command = "overlay_insert_bytes", }), .placement = if (@hasDecl(options, "placement")) options.placement else .top_center, @@ -105,6 +114,7 @@ pub fn Create(options: type) type { try self.query.appendSlice(self.allocator, initial_query); } try self.start_query(0); + try mv.floating_views.add(self.modal.widget()); try mv.floating_views.add(self.menu.container_widget); if (@hasDecl(options, "handle_event")) blk: { @@ -123,8 +133,10 @@ pub fn Create(options: type) type { if (@hasDecl(options, "deinit")) options.deinit(self); self.entries.deinit(self.allocator); - if (tui.mainview()) |mv| + if (tui.mainview()) |mv| { mv.floating_views.remove(self.menu.container_widget); + mv.floating_views.remove(self.modal.widget()); + } self.logger.deinit(); self.allocator.destroy(self); } @@ -359,7 +371,7 @@ pub fn Create(options: type) type { try self.query.appendSlice(self.allocator, buf[0..bytes]); if (@hasDecl(options, "update_query")) options.update_query(self, self.query.items); - // std.log.debug("insert_code_point: '{s}'", .{self.query.items}); + std.log.debug("insert_code_point: '{s}'", .{self.query.items}); return self.start_query(0); } @@ -367,7 +379,7 @@ pub fn Create(options: type) type { try self.query.appendSlice(self.allocator, bytes); if (@hasDecl(options, "update_query")) options.update_query(self, self.query.items); - // std.log.debug("insert_bytes: '{s}'", .{self.query.items}); + std.log.debug("insert_bytes: '{s}'", .{self.query.items}); return self.start_query(0); } @@ -413,7 +425,7 @@ pub fn Create(options: type) type { pub fn palette_menu_down(self: *Self, _: Ctx) Result { if (self.menu.selected) |selected| { - if (selected == self.view_rows -| 1 and + if (selected == self.view_rows - 1 and self.view_pos + self.view_rows < self.total_items) { self.view_pos += 1;