From c93f829cd5274ed5ceee6686d01d39a51e27e6df Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 17 Mar 2026 22:21:42 +0100 Subject: [PATCH] fix: sort files in each directory of the file tree --- src/tui/mode/overlay/file_tree_palette.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tui/mode/overlay/file_tree_palette.zig b/src/tui/mode/overlay/file_tree_palette.zig index e29575f..13657d5 100644 --- a/src/tui/mode/overlay/file_tree_palette.zig +++ b/src/tui/mode/overlay/file_tree_palette.zig @@ -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)