Compare commits

...

4 commits

4 changed files with 35 additions and 23 deletions

View file

@ -71,6 +71,7 @@ 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 = "",
@ -158,6 +159,11 @@ pub const KeybindMode = enum {
ignore_alt_text_modifiers,
};
pub const DropdownKeybindMode = enum {
standard,
noninvasive,
};
pub const InitialFindQuery = enum {
empty,
selection,

View file

@ -375,7 +375,7 @@
["right_control", "palette_menu_activate_quick"]
]
},
"overlay/dropdown": {
"overlay/dropdown-noninvasive": {
"inherit": "normal",
"press": [
["alt+f9", "dropdown_next_widget_style"],
@ -388,6 +388,19 @@
["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"],

View file

@ -30,6 +30,7 @@ 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 = .{};
@ -88,14 +89,16 @@ 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))
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| self.logger.err(module_name, e);
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);
}
}
}
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, "");
@ -295,6 +298,8 @@ 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 {

View file

@ -29,7 +29,6 @@ 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),
@ -68,17 +67,6 @@ 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,
@ -93,7 +81,10 @@ pub fn Create(options: type) type {
.query = .empty,
.view_rows = get_view_rows(tui.screen()),
.entries = .empty,
.mode = try keybind.mode("overlay/dropdown", allocator, .{
.mode = try keybind.mode(switch (tui.config().dropdown_keybinds) {
.standard => "overlay/dropdown",
.noninvasive => "overlay/dropdown-noninvasive",
}, allocator, .{
.insert_command = "overlay_insert_bytes",
}),
.placement = if (@hasDecl(options, "placement")) options.placement else .top_center,
@ -114,7 +105,6 @@ 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: {
@ -133,10 +123,8 @@ 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);
}
@ -371,7 +359,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);
}
@ -379,7 +367,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);
}
@ -425,7 +413,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;