From c796def9671de4757c8eb0730f2bea34e227a6c3 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 10 Nov 2025 10:59:36 +0100 Subject: [PATCH] refactor: add editor.sort_matches function --- src/tui/editor.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 5308fba..c8f2dc2 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -1922,6 +1922,20 @@ pub const Editor = struct { self.match_done_token = self.match_token; } + pub fn sort_matches(self: *Self) void { + const less_fn = struct { + fn less_fn(_: void, lhs_: ?Match, rhs_: ?Match) bool { + const lhs = lhs_ orelse return false; + const rhs = rhs_ orelse return false; + return if (lhs.begin.row == rhs.begin.row) + lhs.begin.col < rhs.begin.col + else + lhs.begin.row < rhs.begin.row; + } + }.less_fn; + std.mem.sort(?Match, self.matches.items, {}, less_fn); + } + pub fn init_matches_update(self: *Self) void { self.cancel_all_matches(); self.match_token += 1;