feat: add alternate select (shift+enter) to symbols palette that selects the symbol

This commit is contained in:
CJ van den Berg 2026-02-06 16:23:30 +01:00
parent da8677357f
commit 21dc4477f7
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 44 additions and 2 deletions

View file

@ -3909,7 +3909,7 @@ pub const Editor = struct {
try self.with_cursels_const(root, &move_to_match_bracket, self.metrics);
self.clamp();
}
pub const goto_bracket_meta: Meta = .{ .description = "goto matching bracket" };
pub const goto_bracket_meta: Meta = .{ .description = "Goto matching bracket" };
pub fn move_or_select_to_char_right(self: *Self, ctx: Context) Result {
const selected = if (self.get_primary().selection) |_| true else false;
@ -6371,6 +6371,36 @@ pub const Editor = struct {
}
pub const focus_on_range_meta: Meta = .{ .arguments = &.{ .integer, .integer, .integer, .integer } };
pub fn select_range(self: *Self, ctx: Context) Result {
var sel: Selection = .{};
if (!try ctx.args.match(.{
tp.extract(&sel.begin.row),
tp.extract(&sel.begin.col),
tp.extract(&sel.end.row),
tp.extract(&sel.end.col),
})) return error.InvalidSelectRangeArgument;
self.cancel_all_matches();
self.add_match_internal(sel.begin.row + 1, sel.begin.col, sel.end.row + 1, sel.end.col);
const primary = self.get_primary();
primary.selection = sel;
const cursor = sel.end;
primary.cursor = cursor;
const range_height = sel.end.row - sel.begin.row + 1;
const view_height = self.view.rows;
const scroll_cursor_min_border_distance = tui.config().scroll_cursor_min_border_distance;
const offset = if (range_height > view_height - @min(view_height, scroll_cursor_min_border_distance * 2))
scroll_cursor_min_border_distance
else
(view_height / 2) - (range_height / 2);
const row = if (cursor.row > offset)
cursor.row - offset
else
0;
self.update_scroll_dest_abs(row);
}
pub const select_range_meta: Meta = .{ .arguments = &.{ .integer, .integer, .integer, .integer } };
pub fn goto_byte_offset(self: *Self, ctx: Context) Result {
try self.send_editor_jump_source();
var offset: usize = 0;

View file

@ -148,11 +148,23 @@ fn find_closest(palette: *Type) ?usize {
}
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
const self = menu.*.opts.ctx;
const editor = tui.get_active_editor() orelse return;
editor.clear_matches();
_, _, _, const sel = get_values(button.opts.label);
tp.self_pid().send(.{ "cmd", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ sel.begin.row + 1, sel.begin.col + 1 } }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
switch (self.activate) {
.normal => tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{
sel.begin.row + 1,
sel.begin.col + 1,
} }) catch |e| menu.*.opts.ctx.logger.err(module_name, e),
.alternate => tp.self_pid().send(.{ "cmd", "select_range", .{
sel.begin.row,
sel.begin.col,
sel.end.row,
sel.end.col,
} }) catch {},
}
}
pub fn updated(palette: *Type, button_: ?*Type.ButtonType) !void {