refactor: add selection_pos_to_width and get_replace_selection functions
This commit is contained in:
parent
390fbd51ff
commit
6ae176a8ac
2 changed files with 14 additions and 0 deletions
|
@ -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 } {
|
||||
var pos = content;
|
||||
var offset = content.len;
|
||||
|
|
|
@ -130,6 +130,15 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, Buffer
|
|||
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 {
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue