fix: align sidebar search matching

This commit is contained in:
t8y2
2026-05-26 11:57:12 +08:00
parent f895bb4de5
commit 7bdacc52ba
2 changed files with 14 additions and 0 deletions
+3
View File
@@ -31,6 +31,9 @@ function matchesSubsequence(text: string, query: string): boolean {
let j = 0;
for (let i = 0; i < text.length && j < query.length; i++) {
if (isWordBoundary(text, i) && i > 0) {
j = 0;
}
if (text[i] === query[j]) j++;
}
return j === query.length;
+11
View File
@@ -21,3 +21,14 @@ test("keeps one-character fuzzy matches disabled", () => {
assert.equal(matchSidebarLabel("orders", "r")?.kind, "substring");
assert.equal(matchSidebarLabel("orders", "x"), null);
});
test("does not match loose subsequences that object search would exclude", () => {
assert.equal(matchSidebarLabel("sys_role_data_scope", "roles"), null);
assert.equal(matchSidebarLabel("sys_role_data_scope", "role")?.kind, "word-prefix");
});
test("keeps fuzzy subsequence matching inside a single identifier word", () => {
assert.equal(matchSidebarLabel("orders", "odr")?.kind, "fuzzy");
assert.equal(matchSidebarLabel("user_profile", "up")?.kind, "abbreviation");
assert.equal(matchSidebarLabel("user_profile", "urf"), null);
});