feat: pre-select symbol at the primary cursor in symbol_palette
This commit is contained in:
parent
fc244eabb6
commit
ae6df9dba8
1 changed files with 14 additions and 0 deletions
|
|
@ -121,6 +121,9 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
}.less_fn;
|
||||
std.mem.sort(Entry, palette.entries.items, {}, less_fn);
|
||||
|
||||
palette.initial_selected = find_closest(palette);
|
||||
palette.quick_activate_enabled = false;
|
||||
|
||||
const total_width = total_row_width();
|
||||
return 2 + if (max_cols_len > label.len + 3) total_width - max_label_len else label.len + 1 - max_cols_len;
|
||||
}
|
||||
|
|
@ -185,6 +188,17 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, ed.Sel
|
|||
return .{ label_, container, kind, range };
|
||||
}
|
||||
|
||||
fn find_closest(palette: *Type) ?usize {
|
||||
const editor = tui.get_active_editor() orelse return null;
|
||||
const cursor = editor.get_primary().cursor;
|
||||
for (palette.entries.items, 0..) |entry, idx| {
|
||||
_, _, _, const sel = get_values(entry.cbor);
|
||||
if (cursor.within(sel))
|
||||
return idx + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
||||
_, _, _, 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue