fix(sidebar): support separator-blind table search

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-07-22 17:17:37 +08:00
1 parent 6e34a342e2
commit ffbd32d203
2 files changed
+365

No files matched your search

@@ -15,6 +15,18 @@ function isWordBoundary(text: string, index: number): boolean {
return prev === "_" || prev === "-" || prev === "." || prev === " " || prev === "/" || prev === "\\";
}
const SEPARATOR_RE = /[_\-. /\\]/g;
/**
* Strip common word separators from a label to enable matching that
* ignores separator characters. For example, searching "delo" will
* match "del_order" because the stripped form "delorder" starts with
* "delo".
*/
function stripSeparators(text: string): string {
return text.replace(SEPARATOR_RE, "");
}
function matchesWordPrefix(text: string, query: string): boolean {
for (let i = 0; i < text.length; i++) {
if (isWordBoundary(text, i) && text.startsWith(query, i)) return true;
@@ -55,6 +67,15 @@ function matchSidebarLabelWithRegex(label: string, query: string, regex: RegExp
if (query.length >= 2 && matchesAbbreviation(label, query)) return { kind: "abbreviation", score: 60 };
if (matchesSubsequence(label, query)) return { kind: "fuzzy", score: 40 };
// Separator-blind matching: strip underscores, hyphens, dots, spaces,
// and slashes, then try again. This lets "delo" match "del_order"
// without typing the underscore separator between prefix and name.
const stripped = stripSeparators(label);
if (stripped !== label && stripped.length >= query.length) {
if (stripped.startsWith(query)) return { kind: "word-prefix", score: 65 };
if (stripped.includes(query)) return { kind: "substring", score: 55 };
}
return null;
}