From a5df57f8248136fb7b93c8bb2722a81eb143e9e4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 17 Mar 2026 22:27:35 +0100 Subject: [PATCH] fix: sort filelist items --- src/tui/filelist_view.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tui/filelist_view.zig b/src/tui/filelist_view.zig index ff820e1..8e2da8a 100644 --- a/src/tui/filelist_view.zig +++ b/src/tui/filelist_view.zig @@ -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;