Compare commits

..

3 commits

2 changed files with 32 additions and 7 deletions

View file

@ -32,6 +32,7 @@ enable_auto_save: bool = false,
limit_auto_save_file_types: ?[]const []const u8 = null, // null means *all* limit_auto_save_file_types: ?[]const []const u8 = null, // null means *all*
enable_prefix_keyhints: bool = true, enable_prefix_keyhints: bool = true,
enable_auto_find: bool = true, enable_auto_find: bool = true,
initial_find_query: InitialFindQuery = .selection,
ignore_filter_stderr: bool = false, ignore_filter_stderr: bool = false,
auto_run_time_seconds: usize = 120, //seconds auto_run_time_seconds: usize = 120, //seconds
@ -151,3 +152,10 @@ pub const KeybindMode = enum {
normal, normal,
ignore_alt_text_modifiers, ignore_alt_text_modifiers,
}; };
pub const InitialFindQuery = enum {
empty,
selection,
last_query,
selection_or_last_query,
};

View file

@ -51,10 +51,14 @@ pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tu
var query: []const u8 = undefined; var query: []const u8 = undefined;
if (ctx.args.match(.{ cbor.extract(&self.find_mode), cbor.extract(&query) }) catch false) { if (ctx.args.match(.{ cbor.extract(&self.find_mode), cbor.extract(&query) }) catch false) {
try self.input_.appendSlice(self.allocator, query); try self.input_.appendSlice(self.allocator, query);
} else if (editor.get_primary().selection) |sel| ret: { } else switch (tui.config().initial_find_query) {
const text = editor.get_selection(sel, self.allocator) catch break :ret; .empty => {},
defer self.allocator.free(text); .selection => try self.set_from_current_selection(editor),
try self.input_.appendSlice(self.allocator, text); .last_query => self.find_history_prev(),
.selection_or_last_query => {
try self.set_from_current_selection(editor);
if (self.input_.items.len == 0) self.find_history_prev();
},
} }
var mode = try keybind.mode("mini/find", allocator, .{ var mode = try keybind.mode("mini/find", allocator, .{
.insert_command = "mini_mode_insert_bytes", .insert_command = "mini_mode_insert_bytes",
@ -74,6 +78,14 @@ pub fn deinit(self: *Self) void {
self.allocator.destroy(self); self.allocator.destroy(self);
} }
fn set_from_current_selection(self: *Self, editor: *ed.Editor) !void {
if (editor.get_primary().selection) |sel| ret: {
const text = editor.get_selection(sel, self.allocator) catch break :ret;
defer self.allocator.free(text);
try self.input_.appendSlice(self.allocator, text);
}
}
pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool {
var text: []const u8 = undefined; var text: []const u8 = undefined;
@ -113,8 +125,7 @@ fn flush_input(self: *Self) !void {
.case_folded => .case_folded, .case_folded => .case_folded,
}); });
} else { } else {
self.editor.get_primary().selection = null; self.reset();
self.editor.init_matches_update();
} }
} }
@ -127,9 +138,15 @@ fn cmd(self: *Self, name_: []const u8, ctx: command.Context) tp.result {
return command.executeName(name_, ctx); return command.executeName(name_, ctx);
} }
fn cancel(self: *Self) void { fn reset(self: *Self) void {
self.editor.get_primary().selection = null;
self.editor.get_primary().cursor = self.start_cursor; self.editor.get_primary().cursor = self.start_cursor;
self.editor.scroll_to(self.start_view.row); self.editor.scroll_to(self.start_view.row);
self.editor.clear_matches();
}
fn cancel(self: *Self) void {
self.reset();
command.executeName("exit_mini_mode", .{}) catch {}; command.executeName("exit_mini_mode", .{}) catch {};
} }