feat: add initial_find_query config option
This commit is contained in:
parent
f09bbbb7a9
commit
6de60f681f
2 changed files with 24 additions and 4 deletions
|
|
@ -32,6 +32,7 @@ enable_auto_save: bool = false,
|
|||
limit_auto_save_file_types: ?[]const []const u8 = null, // null means *all*
|
||||
enable_prefix_keyhints: bool = true,
|
||||
enable_auto_find: bool = true,
|
||||
initial_find_query: InitialFindQuery = .selection,
|
||||
ignore_filter_stderr: bool = false,
|
||||
|
||||
auto_run_time_seconds: usize = 120, //seconds
|
||||
|
|
@ -151,3 +152,10 @@ pub const KeybindMode = enum {
|
|||
normal,
|
||||
ignore_alt_text_modifiers,
|
||||
};
|
||||
|
||||
pub const InitialFindQuery = enum {
|
||||
empty,
|
||||
selection,
|
||||
last_query,
|
||||
selection_or_last_query,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,10 +51,14 @@ pub fn create(allocator: Allocator, ctx: command.Context) !struct { tui.Mode, tu
|
|||
var query: []const u8 = undefined;
|
||||
if (ctx.args.match(.{ cbor.extract(&self.find_mode), cbor.extract(&query) }) catch false) {
|
||||
try self.input_.appendSlice(self.allocator, query);
|
||||
} else 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);
|
||||
} else switch (tui.config().initial_find_query) {
|
||||
.empty => {},
|
||||
.selection => try self.set_from_current_selection(editor),
|
||||
.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, .{
|
||||
.insert_command = "mini_mode_insert_bytes",
|
||||
|
|
@ -74,6 +78,14 @@ pub fn deinit(self: *Self) void {
|
|||
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 {
|
||||
var text: []const u8 = undefined;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue