refactor: add selection_pos_to_width and get_replace_selection functions

This commit is contained in:
CJ van den Berg 2025-10-02 16:27:16 +02:00
parent 390fbd51ff
commit 6ae176a8ac
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 14 additions and 0 deletions

View file

@ -5602,6 +5602,11 @@ pub const Editor = struct {
} }
} }
pub fn selection_pos_to_width(self: *Self, sel_: Selection) ?Selection {
const root = self.buf_root() catch return null;
return sel_.from_pos(root, self.metrics) catch null;
}
fn count_lines(content: []const u8) struct { usize, usize } { fn count_lines(content: []const u8) struct { usize, usize } {
var pos = content; var pos = content;
var offset = content.len; var offset = content.len;

View file

@ -130,6 +130,15 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, Buffer
return .{ label_, sort_text, kind, replace }; return .{ label_, sort_text, kind, replace };
} }
fn get_replace_selection(replace: Buffer.Selection) ?Buffer.Selection {
return if (tui.get_active_editor()) |edt|
edt.selection_pos_to_width(replace)
else if (replace.empty())
null
else
replace;
}
fn select(menu: **Type.MenuState, button: *Type.ButtonState) void { fn select(menu: **Type.MenuState, button: *Type.ButtonState) void {
const label_, _, _, _ = get_values(button.opts.label); const label_, _, _, _ = 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", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);