Compare commits
No commits in common. "f9bbb558149dea7d437bb0579d246448313376ac" and "310dadb9be295f0014eaa1bf3aecfb3da1dc31f3" have entirely different histories.
f9bbb55814
...
310dadb9be
4 changed files with 20 additions and 71 deletions
|
|
@ -5711,37 +5711,6 @@ pub const Editor = struct {
|
|||
}
|
||||
pub const goto_line_and_column_meta: Meta = .{ .arguments = &.{ .integer, .integer } };
|
||||
|
||||
pub fn focus_on_range(self: *Self, ctx: Context) Result {
|
||||
var sel: Selection = .{};
|
||||
var pos_type: PosType = .column;
|
||||
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),
|
||||
tp.extract(&pos_type),
|
||||
})) return error.InvalidFocusOnRangeArgument;
|
||||
|
||||
self.cancel_all_selections();
|
||||
const root = self.buf_root() catch return;
|
||||
if (pos_type == .byte)
|
||||
sel = sel.from_pos(root, self.metrics) catch return;
|
||||
const primary = self.get_primary();
|
||||
try primary.cursor.move_to(
|
||||
root,
|
||||
sel.begin.row,
|
||||
sel.begin.col,
|
||||
self.metrics,
|
||||
);
|
||||
primary.selection = sel;
|
||||
if (self.view.is_visible(&primary.cursor))
|
||||
self.clamp()
|
||||
else
|
||||
try self.scroll_view_center(.{});
|
||||
self.need_render();
|
||||
}
|
||||
pub const focus_on_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;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ pub fn Create(options: type) type {
|
|||
longest_hint: usize = 0,
|
||||
initial_selected: ?usize = null,
|
||||
placement: Placement,
|
||||
quick_activate_enabled: bool = true,
|
||||
|
||||
items: usize = 0,
|
||||
view_rows: usize,
|
||||
|
|
@ -78,7 +77,7 @@ pub fn Create(options: type) type {
|
|||
else
|
||||
ModalBackground.Options(*Self).on_render_default
|
||||
else
|
||||
ModalBackground.Options(*Self).on_render_dim,
|
||||
ModalBackground.Options(*Self).on_render_default,
|
||||
}),
|
||||
.menu = try Menu.create(*Self, allocator, tui.plane(), .{
|
||||
.ctx = self,
|
||||
|
|
@ -112,6 +111,8 @@ pub fn Create(options: type) type {
|
|||
try options.load_entries_with_args(self, ctx)
|
||||
else
|
||||
try options.load_entries(self);
|
||||
if (self.entries.items.len > 0)
|
||||
self.initial_selected = self.menu.selected;
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
options.restore_state(self) catch {};
|
||||
if (@hasDecl(options, "initial_query")) blk: {
|
||||
|
|
@ -554,9 +555,7 @@ pub fn Create(options: type) type {
|
|||
pub const palette_menu_activate_meta: Meta = .{};
|
||||
|
||||
pub fn palette_menu_activate_quick(self: *Self, _: Ctx) Result {
|
||||
if (!self.quick_activate_enabled) return;
|
||||
if (self.menu.selected orelse 0 > 0) self.menu.activate_selected();
|
||||
self.quick_activate_enabled = false;
|
||||
}
|
||||
pub const palette_menu_activate_quick_meta: Meta = .{};
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ const columns: [3]Column = .{
|
|||
|
||||
pub const Entry = struct {
|
||||
label: []const u8,
|
||||
range: ed.Selection,
|
||||
row: usize,
|
||||
cbor: []const u8,
|
||||
};
|
||||
|
||||
|
|
@ -104,8 +104,8 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
while (iter.len > 0) {
|
||||
var cbor_item: []const u8 = undefined;
|
||||
if (!try cbor.matchValue(&iter, cbor.extract_cbor(&cbor_item))) return error.BadCompletion;
|
||||
const label_, const parent_, const kind, const sel = get_values(cbor_item);
|
||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .range = sel };
|
||||
const label_, const parent_, const kind, const row, _ = get_values(cbor_item);
|
||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_[0..@min(columns[0].max_width, label_.len)], .row = row };
|
||||
|
||||
const current_lengths: [3]usize = .{ label_.len, parent_.len, kind_name(@enumFromInt(kind)).len };
|
||||
const label_len: u8 = @truncate(if (label_.len > columns[0].max_width) columns[0].max_width else label_.len);
|
||||
|
|
@ -116,14 +116,11 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
|
||||
const less_fn = struct {
|
||||
fn less_fn(_: void, lhs: Entry, rhs: Entry) bool {
|
||||
return lhs.range.begin.row < rhs.range.begin.row;
|
||||
return lhs.row < rhs.row;
|
||||
}
|
||||
}.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;
|
||||
}
|
||||
|
|
@ -150,7 +147,7 @@ pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Wi
|
|||
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&item_cbor)) catch false)) return false;
|
||||
if (!(cbor.matchValue(&iter, cbor.extract_cbor(&matches_cbor)) catch false)) return false;
|
||||
|
||||
const label_, const container, const kind, _ = get_values(item_cbor);
|
||||
const label_, const container, const kind, _, _ = get_values(item_cbor);
|
||||
const icon_: []const u8 = kind_icon(@enumFromInt(kind));
|
||||
const color: u24 = 0x0;
|
||||
var value: std.Io.Writer.Allocating = .init(palette.allocator);
|
||||
|
|
@ -163,20 +160,21 @@ pub fn on_render_menu(palette: *Type, button: *Type.ButtonType, theme: *const Wi
|
|||
return tui.render_file_item(&button.plane, value.written(), icon_, color, indicator, matches_cbor, button.active, selected, button.hover, theme);
|
||||
}
|
||||
|
||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, ed.Selection } {
|
||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, usize, usize } {
|
||||
var label_: []const u8 = "";
|
||||
var container: []const u8 = "";
|
||||
var kind: u8 = 0;
|
||||
var range: ed.Selection = .{};
|
||||
var row: usize = 0;
|
||||
var col: usize = 0;
|
||||
_ = cbor.match(item_cbor, .{
|
||||
cbor.any, // file_path
|
||||
cbor.extract(&label_), // name
|
||||
cbor.extract(&container), // parent_name
|
||||
cbor.extract(&kind), // kind
|
||||
cbor.extract(&range.begin.row), // range.begin.row
|
||||
cbor.extract(&range.begin.col), // range.begin.col
|
||||
cbor.extract(&range.end.row), // range.end.row
|
||||
cbor.extract(&range.end.col), // range.end.col
|
||||
cbor.extract(&row), // range.begin.row
|
||||
cbor.extract(&col), // range.begin.col
|
||||
cbor.any, // range.end.row
|
||||
cbor.any, // range.end.col
|
||||
cbor.any, // tags
|
||||
cbor.any, // selectionRange.begin.row
|
||||
cbor.any, // selectionRange.begin.col
|
||||
|
|
@ -185,33 +183,19 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, u8, ed.Sel
|
|||
cbor.any, // deprecated
|
||||
cbor.any, // detail
|
||||
}) catch false;
|
||||
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;
|
||||
var previous: usize = 0;
|
||||
for (palette.entries.items, 0..) |entry, idx| {
|
||||
_, _, _, const sel = get_values(entry.cbor);
|
||||
if (cursor.within(sel))
|
||||
return idx + 1;
|
||||
if (cursor.row < sel.begin.row) return previous + 1;
|
||||
previous = idx;
|
||||
}
|
||||
return null;
|
||||
return .{ label_, container, kind, row, col };
|
||||
}
|
||||
|
||||
fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
||||
_, _, _, const sel = get_values(button.opts.label);
|
||||
_, _, _, const row, const col = 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);
|
||||
tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ row + 1, col + 1 } }) catch |e| menu.*.opts.ctx.logger.err(module_name, e);
|
||||
}
|
||||
|
||||
pub fn updated(palette: *Type, button_: ?*Type.ButtonType) !void {
|
||||
const button = button_ orelse return cancel(palette);
|
||||
_, _, _, const sel = get_values(button.opts.label);
|
||||
tp.self_pid().send(.{ "cmd", "focus_on_range", .{ sel.begin.row, sel.begin.col, sel.end.row, sel.end.col, ed.PosType.byte } }) catch {};
|
||||
_, _, _, const row, const col = get_values(button.opts.label);
|
||||
tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{ row + 1, col + 1 } }) catch {};
|
||||
}
|
||||
|
||||
pub fn cancel(palette: *Type) !void {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ pub const Type = @import("palette.zig").Create(@This());
|
|||
pub const label = "Search themes";
|
||||
pub const name = " theme";
|
||||
pub const description = "theme";
|
||||
pub const modal_dim = false;
|
||||
pub const placement = .top_right;
|
||||
|
||||
pub const Entry = struct {
|
||||
label: []const u8,
|
||||
|
|
@ -41,7 +39,6 @@ pub fn load_entries(palette: *Type) !usize {
|
|||
};
|
||||
longest_hint = @max(longest_hint, theme.name.len);
|
||||
}
|
||||
palette.quick_activate_enabled = false;
|
||||
return longest_hint;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue