Merge branch 'master' into terminal
This commit is contained in:
commit
42d0e541e8
11 changed files with 113 additions and 30 deletions
|
|
@ -111,12 +111,20 @@ pub fn walk(self: *Self, walk_ctx: *anyopaque, f: Widget.WalkFn) bool {
|
|||
return self.menu.container_widget.walk(walk_ctx, f) or f(walk_ctx, Widget.to(self));
|
||||
}
|
||||
|
||||
fn entry_less_than(_: void, a: Entry, b: Entry) bool {
|
||||
const path_order = std.mem.order(u8, a.path, b.path);
|
||||
if (path_order != .eq) return path_order == .lt;
|
||||
if (a.begin_line != b.begin_line) return a.begin_line < b.begin_line;
|
||||
return a.begin_pos < b.begin_pos;
|
||||
}
|
||||
|
||||
pub fn add_item(self: *Self, entry_: Entry) !void {
|
||||
const idx = self.entries.items.len;
|
||||
const entry = (try self.entries.addOne(self.allocator));
|
||||
entry.* = entry_;
|
||||
entry.path = try self.allocator.dupe(u8, entry_.path);
|
||||
entry.lines = try self.allocator.dupe(u8, entry_.lines);
|
||||
std.mem.sort(Entry, self.entries.items, {}, entry_less_than);
|
||||
var label: std.Io.Writer.Allocating = .init(self.allocator);
|
||||
defer label.deinit();
|
||||
cbor.writeValue(&label.writer, idx) catch return;
|
||||
|
|
|
|||
|
|
@ -1286,6 +1286,7 @@ const cmds = struct {
|
|||
.integer, // selectionRange.end.col
|
||||
.boolean, // deprecated
|
||||
.string, //detail
|
||||
.integer, //depth
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ pub fn on_render_menu(self: *Type, button: *Type.ButtonType, theme: *const Widge
|
|||
};
|
||||
return tui.render_symbol(
|
||||
&button.plane,
|
||||
0,
|
||||
values.label,
|
||||
icon_,
|
||||
color,
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
|||
|
||||
return tui.render_symbol(
|
||||
&button.plane,
|
||||
0,
|
||||
values.label,
|
||||
icon_,
|
||||
color,
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ fn receive_project_manager(palette: *Type, _: tp.pid_ref, m: tp.message) Message
|
|||
} else if (try cbor.match(m.buf, .{ "PRJ", "path_done", tp.any, tp.any, tp.any })) {
|
||||
const pending = palette.value.pending_node;
|
||||
palette.value.pending_node = null;
|
||||
if (pending) |p| if (p.children) |*children| sort_children(children);
|
||||
palette.entries.clearRetainingCapacity();
|
||||
if (palette.value.root_node) |root| try build_visible_list(palette, root, 0);
|
||||
palette.longest_hint = max_entry_overhead(palette);
|
||||
|
|
@ -138,6 +139,16 @@ fn receive_project_manager(palette: *Type, _: tp.pid_ref, m: tp.message) Message
|
|||
return true;
|
||||
}
|
||||
|
||||
fn sort_children(children: *std.ArrayList(Node)) void {
|
||||
const less_fn = struct {
|
||||
fn less_fn(_: void, lhs: Node, rhs: Node) bool {
|
||||
if (lhs.type_ != rhs.type_) return lhs.type_ == .folder;
|
||||
return std.mem.lessThan(u8, lhs.name, rhs.name);
|
||||
}
|
||||
}.less_fn;
|
||||
std.mem.sort(Node, children.items, {}, less_fn);
|
||||
}
|
||||
|
||||
fn append_pending_child(palette: *Type, file_name: []const u8, node_type: NodeType, icon_: []const u8, color_: u24) !void {
|
||||
const node = palette.value.pending_node orelse return;
|
||||
if (node.children == null)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ 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 sel = get_values(cbor_item);
|
||||
const label_, _, _, const sel, _ = get_values(cbor_item);
|
||||
const label_len_ = tui.egc_chunk_width(label_, 0, 1);
|
||||
(try palette.entries.addOne(palette.allocator)).* = .{ .cbor = cbor_item, .label = label_, .range = sel };
|
||||
|
||||
|
|
@ -89,11 +89,12 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
|||
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, _, const indent = get_values(item_cbor);
|
||||
const icon_: []const u8 = kind.icon();
|
||||
const color: u24 = 0x0;
|
||||
return tui.render_symbol(
|
||||
&button.plane,
|
||||
indent,
|
||||
label_,
|
||||
icon_,
|
||||
color,
|
||||
|
|
@ -110,10 +111,11 @@ pub fn on_render_menu(_: *Type, button: *Type.ButtonType, theme: *const Widget.T
|
|||
);
|
||||
}
|
||||
|
||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection } {
|
||||
fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind, ed.Selection, u8 } {
|
||||
var label_: []const u8 = "";
|
||||
var container: []const u8 = "";
|
||||
var kind: u8 = 0;
|
||||
var depth: u8 = 0;
|
||||
var range: ed.Selection = .{};
|
||||
_ = cbor.match(item_cbor, .{
|
||||
cbor.any, // file_path
|
||||
|
|
@ -131,8 +133,9 @@ fn get_values(item_cbor: []const u8) struct { []const u8, []const u8, SymbolKind
|
|||
cbor.any, // selectionRange.end.col
|
||||
cbor.any, // deprecated
|
||||
cbor.any, // detail
|
||||
cbor.extract(&depth), // number of ancestors
|
||||
}) catch false;
|
||||
return .{ label_, container, @enumFromInt(kind), range };
|
||||
return .{ label_, container, @enumFromInt(kind), range, depth };
|
||||
}
|
||||
|
||||
fn find_closest(palette: *Type) ?usize {
|
||||
|
|
@ -140,7 +143,7 @@ fn find_closest(palette: *Type) ?usize {
|
|||
const cursor = editor.get_primary().cursor;
|
||||
var previous: usize = 0;
|
||||
for (palette.entries.items, 0..) |entry, idx| {
|
||||
_, _, _, const sel = get_values(entry.cbor);
|
||||
_, _, _, const sel, _ = get_values(entry.cbor);
|
||||
if (cursor.row < sel.begin.row) return previous + 1;
|
||||
previous = idx;
|
||||
}
|
||||
|
|
@ -151,7 +154,7 @@ fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
|||
const self = menu.*.opts.ctx;
|
||||
const editor = tui.get_active_editor() orelse return;
|
||||
editor.clear_matches();
|
||||
_, _, _, 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);
|
||||
switch (self.activate) {
|
||||
.normal => tp.self_pid().send(.{ "cmd", "goto_line_and_column", .{
|
||||
|
|
@ -169,7 +172,7 @@ fn select(menu: **Type.MenuType, button: *Type.ButtonType, _: Type.Pos) void {
|
|||
|
||||
pub fn updated(palette: *Type, button_: ?*Type.ButtonType) !void {
|
||||
const button = button_ orelse return cancel(palette);
|
||||
_, _, _, const sel = get_values(button.opts.label);
|
||||
_, _, _, 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 } }) catch {};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2423,6 +2423,7 @@ pub fn render_file_vcs_item_cbor(self: *renderer.Plane, file_item_cbor: []const
|
|||
|
||||
pub fn render_symbol(
|
||||
self: *renderer.Plane,
|
||||
indent: u8,
|
||||
symbol: []const u8,
|
||||
icon: []const u8,
|
||||
color: u24,
|
||||
|
|
@ -2456,6 +2457,9 @@ pub fn render_symbol(
|
|||
const icon_width = render_file_icon(self, icon, color);
|
||||
|
||||
self.set_style(style_symbol);
|
||||
|
||||
for (0..indent) |_| _ = self.print(" ", .{}) catch {};
|
||||
|
||||
_ = self.print("{s}", .{symbol}) catch {};
|
||||
|
||||
self.set_style(style_detail);
|
||||
|
|
@ -2473,7 +2477,7 @@ pub fn render_symbol(
|
|||
while (len > 0) : (len -= 1) {
|
||||
if (cbor.matchValue(&iter, cbor.extract(&index)) catch break) {
|
||||
const col = egc_chunk_width(symbol[0..@min(symbol.len, index)], 0, 1);
|
||||
render_match_cell(self, 0, col + 2 + icon_width, theme_) catch break;
|
||||
render_match_cell(self, 0, col + 2 + icon_width + indent, theme_) catch break;
|
||||
} else break;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue