diff options
| author | Fuwn <[email protected]> | 2025-05-16 06:49:28 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-05-16 06:49:28 -0700 |
| commit | ce9b464d23c7cea214d550516da5fd7df4399859 (patch) | |
| tree | a2658354fa189177ed6711ac8048f6c9e40f3139 | |
| parent | feat(CommandPalette): Ignore whitespace when matching query (diff) | |
| download | due.moe-ce9b464d23c7cea214d550516da5fd7df4399859.tar.xz due.moe-ce9b464d23c7cea214d550516da5fd7df4399859.zip | |
refactor(CommandPalette): DRY matching logic
| -rw-r--r-- | src/lib/CommandPalette/CommandPalette.svelte | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/lib/CommandPalette/CommandPalette.svelte b/src/lib/CommandPalette/CommandPalette.svelte index cdf962d7..2d2ec6ee 100644 --- a/src/lib/CommandPalette/CommandPalette.svelte +++ b/src/lib/CommandPalette/CommandPalette.svelte @@ -20,14 +20,18 @@ if (!itemIDs.has(item.url)) itemIDs.set(item.url, index); }); - const doesActionMatch = (action: CommandPaletteAction) => - action.name - .toLowerCase() - .replace(/\s+/g, '') - .includes(search.toLowerCase().replace(/\s+/g, '')) || - action.tags?.some((tag) => - tag.toLowerCase().replace(/\s+/g, '').includes(search.toLowerCase().replace(/\s+/g, '')) + const doesActionMatch = (action: CommandPaletteAction) => { + const doesActionIncludePattern = (query: string, action: string) => { + const normalise = (input: string) => input.toLowerCase().replace(/\s+/g, ''); + + return normalise(query).includes(normalise(action)); + }; + + return ( + doesActionIncludePattern(action.name, search) || + action.tags?.some((tag) => doesActionIncludePattern(tag, search)) ); + }; filtered = []; |