feat(sidebar): add fuzzy search for table/schema filtering

This commit is contained in:
t8y2 2026-05-06 22:49:56 +08:00
parent 4b11506bee
commit 02813f4b9e
1 changed files with 10 additions and 1 deletions

View File

@ -55,8 +55,17 @@ function clearTypeFilter() {
selectedTypes.value = [];
}
function fuzzyMatch(text: string, query: string): boolean {
let j = 0;
for (let i = 0; i < text.length && j < query.length; i++) {
if (text[i] === query[j]) j++;
}
return j === query.length;
}
function matchesQuery(node: TreeNode, q: string): boolean {
if (node.label.toLowerCase().includes(q)) return true;
const label = node.label.toLowerCase();
if (label.includes(q) || fuzzyMatch(label, q)) return true;
return node.children?.some((child) => matchesQuery(child, q)) ?? false;
}