From 0d6d7599aa9d858cc6e916a23cd7a3b9f4c372af Mon Sep 17 00:00:00 2001 From: James Xylight Date: Sun, 16 Feb 2025 14:38:15 -0800 Subject: [PATCH] fix: commands wont focus, popover cant reverse --- .../ui/navbar/commands/Commands.svelte | 22 ++++++++++++------- src/lib/mono/popover/Popover.svelte | 3 +-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/lib/components/ui/navbar/commands/Commands.svelte b/src/lib/components/ui/navbar/commands/Commands.svelte index a71f2a40..bac8e3cf 100644 --- a/src/lib/components/ui/navbar/commands/Commands.svelte +++ b/src/lib/components/ui/navbar/commands/Commands.svelte @@ -27,7 +27,7 @@ profile.data, profileData.profiles, theme.data, - page.data.contextual?.actions + page.data.contextual?.actions, ) }) @@ -37,6 +37,7 @@ let selectedIndex = $state(0) let filteredGroups: Group[] = $state([]) let breadcrumbs: Action[] = $state([]) + let input = $state() function fuzzySearch(text: string, pattern: string): number { const textLower = text.toLowerCase() @@ -95,7 +96,7 @@ score: Math.max( fuzzySearch(action.name, term), fuzzySearch(group.name, term), - action.detail ? fuzzySearch(action.detail, term) : -1 + action.detail ? fuzzySearch(action.detail, term) : -1, ), })) .filter((action) => action.score > 0) @@ -106,7 +107,7 @@ actions: scoredActions, score: Math.max( fuzzySearch(group.name, term), - ...scoredActions.map((a) => a.score) + ...scoredActions.map((a) => a.score), ), } }) @@ -140,7 +141,7 @@ function flattenActions( actions: Action[], - subaction: boolean = true + subaction: boolean = true, ): Action[] { return actions.flatMap((action) => [ action, @@ -237,13 +238,17 @@ if (open) search = '' }) - let flattenedActions = $derived( - filteredGroups.flatMap((group) => group.actions) - ) - $effect(() => { debouncedSearch(search) }) + + onMount(() => { + if (input) input.focus() + }) + + let flattenedActions = $derived( + filteredGroups.flatMap((group) => group.actions), + ) @@ -253,6 +258,7 @@ class="sticky rounded-none border-t-0 border-x-0 focus-within:dark:border-zinc-800" size="lg" placeholder={$t('nav.commands.prompt')} + bind:element={input} />
{#if breadcrumbs.length > 0} diff --git a/src/lib/mono/popover/Popover.svelte b/src/lib/mono/popover/Popover.svelte index b90b1446..6d80b098 100644 --- a/src/lib/mono/popover/Popover.svelte +++ b/src/lib/mono/popover/Popover.svelte @@ -124,8 +124,7 @@ {#if open}