diff --git a/src/lib/commandCenter/commandCenter.svelte b/src/lib/commandCenter/commandCenter.svelte index 1081e2c05..447ccb336 100644 --- a/src/lib/commandCenter/commandCenter.svelte +++ b/src/lib/commandCenter/commandCenter.svelte @@ -14,6 +14,7 @@ }; export const toggleCommandCenter = () => { + console.log('toggleCommandCenter'); if (get(subPanels).length > 0) { clearSubPanels(); } else { @@ -88,8 +89,8 @@ } const handleKeydown = (e) => { - if (isInputEvent(e)) return; if (!$subPanels.length) { + if (isInputEvent(e)) return; keys = [...keys, e.key].slice(-10); resetKeys(); } diff --git a/src/lib/commandCenter/commands.ts b/src/lib/commandCenter/commands.ts index 0000a30b4..7996fd88f 100644 --- a/src/lib/commandCenter/commands.ts +++ b/src/lib/commandCenter/commands.ts @@ -174,9 +174,13 @@ export const commandCenterKeyDownHandler = derived( const { keys, ctrl: meta, shift, alt } = command; - const isMetaPressed = meta ? (isMac() ? event.metaKey : event.ctrlKey) : true; - const isShiftPressed = shift ? event.shiftKey : true; - const isAltPressed = alt ? event.altKey : true; + const isMetaPressed = meta + ? isMac() + ? event.metaKey + : event.ctrlKey + : !(isMac() ? event.metaKey : event.ctrlKey); + const isShiftPressed = shift ? event.shiftKey : !event.shiftKey; + const isAltPressed = alt ? event.altKey : !event.altKey; const commandKeyCodes = keys.map((key) => key.toUpperCase().charCodeAt(0)); const allKeysPressed = recentKeyCodes.join('').includes(commandKeyCodes.join('')); diff --git a/src/lib/commandCenter/panels/root.svelte b/src/lib/commandCenter/panels/root.svelte index b12fd86f2..29476da56 100644 --- a/src/lib/commandCenter/panels/root.svelte +++ b/src/lib/commandCenter/panels/root.svelte @@ -21,7 +21,10 @@ if (search) { searchResults = []; executeSearch(search); - } else searchResults = []; + } else { + searchResults = []; + executeSearch.cancel(); + } } $: results = [ diff --git a/src/lib/commandCenter/panels/template.svelte b/src/lib/commandCenter/panels/template.svelte index 7a98a99b7..702a43607 100644 --- a/src/lib/commandCenter/panels/template.svelte +++ b/src/lib/commandCenter/panels/template.svelte @@ -114,7 +114,7 @@ type Group = { type: 'group'; name: string }; type IndexedOption = Option & { index: number }; function isGroup(item: Option | Group): item is Group { - return 'type' in item && item.type === 'group'; + return !!item && 'type' in item && item.type === 'group'; } const getGroupsAndOptions = (options: Option[]) => { if (!options) return null; @@ -210,7 +210,7 @@ if (isGroup(item)) return false; if (!item.nested) return false; - return !isGroup(prevItem) && !prevItem.nested; + return !isGroup(prevItem) && !prevItem?.nested; }; const isLastNested = (index: number) => { @@ -219,7 +219,7 @@ if (isGroup(item)) return false; if (!item.nested) return false; - return isGroup(nextItem) || !nextItem.nested; + return isGroup(nextItem) || !nextItem?.nested; }; diff --git a/src/lib/helpers/debounce.ts b/src/lib/helpers/debounce.ts index c84175740..afb93f4a2 100644 --- a/src/lib/helpers/debounce.ts +++ b/src/lib/helpers/debounce.ts @@ -5,12 +5,16 @@ export function debounce void>(fn: F, delay: num timeoutID = window.setTimeout(() => fn.apply(this, args), delay) as unknown as ReturnType< typeof setTimeout >; - } as F & { immediate: F }; + } as F & { immediate: F; cancel: () => void }; debounceFn.immediate = ((...args: Parameters) => { clearTimeout(timeoutID); return fn(args); }) as F; + debounceFn.cancel = () => { + clearTimeout(timeoutID); + }; + return debounceFn; } diff --git a/svelte.config.js b/svelte.config.js index e920cd169..ca8f1dd0b 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -21,7 +21,9 @@ const config = { } }, vitePlugin: { - inspector: true + inspector: { + toggleKeyCombo: 'meta-shift-i' + } } };