diff --git a/src/keybind/builtin/helix.json b/src/keybind/builtin/helix.json index a784717..b604d4d 100644 --- a/src/keybind/builtin/helix.json +++ b/src/keybind/builtin/helix.json @@ -384,7 +384,7 @@ ["?", "rfind"], ["N", "extend_search_next"], - ["*", "extend_search_prev"], + ["*", "search_selection"], ["r", "replace"], ["P", "paste_clipboard_before"], @@ -500,7 +500,7 @@ ["] space", "add_newline_below"], ["/", "find"], - ["n", "goto_next_match"], + ["n", "add_next_match_helix"], ["u", "undo"], ["U", "redo"], diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 779e2c4..18d6a0c 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -5282,7 +5282,7 @@ pub const Editor = struct { (history.addOne(self.allocator) catch return).* = new; } - fn set_last_find_query(self: *Self, query: []const u8, match_type: Match.Type) void { + pub fn set_last_find_query(self: *Self, query: []const u8, match_type: Match.Type) void { self.last_find_query_match_type = match_type; if (self.last_find_query) |last| { if (query.ptr != last.ptr) { @@ -5523,14 +5523,18 @@ pub const Editor = struct { } pub const move_cursor_next_match_meta: Meta = .{ .description = "Move cursor to next hightlighted match" }; + pub fn repeat_last_find(self: *Self) Result { + if (self.last_find_query) |last| { + self.find_operation = .goto_next_match; + try self.find_in_buffer(last, self.last_find_query_match_type, .exact); + } + } + pub fn goto_next_match(self: *Self, ctx: Context) Result { try self.send_editor_jump_source(); self.cancel_all_selections(); if (self.matches.items.len == 0) { - if (self.last_find_query) |last| { - self.find_operation = .goto_next_match; - try self.find_in_buffer(last, self.last_find_query_match_type, .exact); - } + try self.repeat_last_find(); } try self.move_cursor_next_match(ctx); try self.send_editor_jump_destination(); diff --git a/src/tui/mode/helix.zig b/src/tui/mode/helix.zig index b40d4ab..cadd990 100644 --- a/src/tui/mode/helix.zig +++ b/src/tui/mode/helix.zig @@ -498,6 +498,30 @@ const cmds_ = struct { ed.get_primary().* = primary; } pub const keep_primary_selection_meta: Meta = .{}; + + pub fn search_selection(_: *void, _: Ctx) Result { + const mv = tui.mainview() orelse return; + const ed = mv.get_active_editor() orelse return; + const sel = ed.get_primary().selection orelse { + ed.logger.print("no selection", .{}); + return; + }; + const query = try ed.get_selection(sel, ed.allocator); + defer ed.allocator.free(query); + ed.match_type = .find; + ed.set_last_find_query(query, .find); + ed.logger.print("set find register to '{s}'", .{query}); + } + pub const search_selection_meta: Meta = .{}; + + pub fn add_next_match_helix(_: *void, _: Ctx) Result { + const mv = tui.mainview() orelse return; + const ed = mv.get_active_editor() orelse return; + if (ed.matches.items.len == 0) + try ed.repeat_last_find(); + try ed.add_cursor_next_match(.{}); + } + pub const add_next_match_helix_meta: Meta = .{}; }; fn match_bracket(root: Buffer.Root, cursel: *CurSel, ctx: command.Context, metrics: Buffer.Metrics) error{Stop}!void {