feat: pre-select symbol at the primary cursor in symbol_palette

This commit is contained in:
CJ van den Berg 2025-11-18 19:59:08 +01:00
parent fc244eabb6
commit ae6df9dba8
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -121,6 +121,9 @@ pub fn load_entries(palette: *Type) !usize {
}.less_fn; }.less_fn;
std.mem.sort(Entry, palette.entries.items, {}, 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(); 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; 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 }; 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 { fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
_, _, _, const sel = get_values(button.opts.label); _, _, _, 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", "exit_overlay_mode" }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);