refactor: just sort completion list instead of filtering it

Also, fix sorting order of equally ranked entries.
This commit is contained in:
CJ van den Berg 2026-01-30 11:22:49 +01:00
parent 518af3ab45
commit b314a4c8c0
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -326,19 +326,18 @@ pub fn Create(options: type) type {
for (self.entries.items) |*entry| { for (self.entries.items) |*entry| {
const match = searcher.scoreMatches(entry.label, query); const match = searcher.scoreMatches(entry.label, query);
if (match.score) |score| (try matches.addOne(self.allocator)).* = .{
(try matches.addOne(self.allocator)).* = .{ .entry = entry,
.entry = entry, .score = match.score orelse 0,
.score = score, .matches = try self.allocator.dupe(usize, match.matches),
.matches = try self.allocator.dupe(usize, match.matches), };
};
} }
if (matches.items.len == 0) return 0; if (matches.items.len == 0) return 0;
const less_fn = struct { const less_fn = struct {
fn less_fn(_: void, lhs: Match, rhs: Match) bool { fn less_fn(_: void, lhs: Match, rhs: Match) bool {
return if (lhs.score == rhs.score) return if (lhs.score == rhs.score)
lhs.entry.label.len < rhs.entry.label.len std.mem.order(u8, lhs.entry.sort_text, rhs.entry.sort_text) == .lt
else else
lhs.score > rhs.score; lhs.score > rhs.score;
} }