fix(tui): prioritize exact fuzzy matches

This commit is contained in:
Armin Ronacher
2026-05-04 20:24:13 +02:00
parent 6b18cdbac1
commit 1bc640e53a
2 changed files with 11 additions and 0 deletions

View File

@@ -60,6 +60,10 @@ export function fuzzyMatch(query: string, text: string): FuzzyMatch {
return { matches: false, score: 0 };
}
if (normalizedQuery === textLower) {
score -= 100;
}
return { matches: true, score };
};

View File

@@ -83,6 +83,13 @@ describe("fuzzyFilter", () => {
assert.strictEqual(result[0], "app");
});
it("prioritizes exact matches over longer prefix matches", () => {
const items = ["clone", "cl"];
const result = fuzzyFilter(items, "cl", (x: string) => x);
assert.deepStrictEqual(result, ["cl", "clone"]);
});
it("works with custom getText function", () => {
const items = [
{ name: "foo", id: 1 },