fix: sort filelist items

This commit is contained in:
CJ van den Berg 2026-03-17 22:27:35 +01:00
parent c93f829cd5
commit a5df57f824
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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;