From eb46131a2cd0ab1b193642e83130ddb0de400902 Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 14 Dec 2023 22:28:21 +0800 Subject: [PATCH] prevent cmdk short keys --- .../main/stageView/iFrame/hooks/useCmdk.ts | 13 ++---------- src/pages/main/hooks/useCmdk.ts | 20 ++++++------------- src/pages/main/hooks/useCmdkModal.ts | 7 +------ 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/components/main/stageView/iFrame/hooks/useCmdk.ts b/src/components/main/stageView/iFrame/hooks/useCmdk.ts index e6be9c65..a519dcb5 100644 --- a/src/components/main/stageView/iFrame/hooks/useCmdk.ts +++ b/src/components/main/stageView/iFrame/hooks/useCmdk.ts @@ -78,17 +78,6 @@ export const useCmdk = ({ break; // Match found, exit the outer loop } } - // prevent chrome default short keys - if ( - action === "Save" || - action === "Download" || - action === "Duplicate" || - action === "Group" || - action === "UnGroup" - ) { - e.preventDefault(); - } - if (isEditingRef.current) { // for content-editing if ( @@ -133,6 +122,8 @@ export const useCmdk = ({ dispatch(setCurrentCommand({ action })); } } + + action && e.preventDefault(); }, [osType, cmdkReferenceData], ); diff --git a/src/pages/main/hooks/useCmdk.ts b/src/pages/main/hooks/useCmdk.ts index 19036505..6d195b96 100644 --- a/src/pages/main/hooks/useCmdk.ts +++ b/src/pages/main/hooks/useCmdk.ts @@ -274,22 +274,14 @@ export const useCmdk = ({ cmdkReferenceData, importProject }: IUseCmdk) => { break; // Match found, exit the outer loop } } - // prevent chrome default short keys - if ( - action === "Save" || - action === "Download" || - action === "Duplicate" || - action === "Group" || - action === "UnGroup" - ) { - e.preventDefault(); - } - - if (cmdkOpen) return; if (action) { - LogAllow && console.log("action to be run by cmdk: ", action); - dispatch(setCurrentCommand({ action })); + if (!cmdkOpen) { + LogAllow && console.log("action to be run by cmdk: ", action); + dispatch(setCurrentCommand({ action })); + } } + + action && e.preventDefault(); }, [osType, cmdkOpen, cmdkReferenceData], ); diff --git a/src/pages/main/hooks/useCmdkModal.ts b/src/pages/main/hooks/useCmdkModal.ts index 0a8ebc15..e356b1d1 100644 --- a/src/pages/main/hooks/useCmdkModal.ts +++ b/src/pages/main/hooks/useCmdkModal.ts @@ -21,13 +21,8 @@ export const useCmdkModal = () => { string | null | undefined >(); - const debouncedCmdkOpen = useCallback( - debounce(() => dispatch(setCmdkOpen(true)), ShortDelay), - [], - ); useEffect(() => { - cmdkPages.length && debouncedCmdkOpen(); - // cmdkPages.length && dispatch(setCmdkOpen(true)); + cmdkPages.length && dispatch(setCmdkOpen(true)); dispatch(setCurrentCmdkPage([...cmdkPages].pop() || "")); }, [cmdkPages]); useEffect(() => {