From c0932093385e04c119f982f50923ed916b58ed0e Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Fri, 7 Apr 2023 17:01:52 +0530 Subject: [PATCH] fix: shortcut combination key bug fix (#733) * fix: shortcut combination key bug fix * refactor: code refactor --- .../command-palette/command-pallette.tsx | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/apps/app/components/command-palette/command-pallette.tsx b/apps/app/components/command-palette/command-pallette.tsx index 650ab5a65..cc11fc600 100644 --- a/apps/app/components/command-palette/command-pallette.tsx +++ b/apps/app/components/command-palette/command-pallette.tsx @@ -177,46 +177,48 @@ export const CommandPalette: React.FC = () => { const handleKeyDown = useCallback( (e: KeyboardEvent) => { + const singleShortcutKeys = ["p", "v", "d", "h", "q", "m"]; + const { key, ctrlKey, metaKey, altKey, shiftKey } = e; + const keyPressed = key.toLowerCase(); if ( !(e.target instanceof HTMLTextAreaElement) && !(e.target instanceof HTMLInputElement) && !(e.target as Element).classList?.contains("remirror-editor") ) { - if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") { + if ((ctrlKey || metaKey) && keyPressed === "k") { e.preventDefault(); setIsPaletteOpen(true); - } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "c") { - if (e.altKey) { + } else if ((ctrlKey || metaKey) && keyPressed === "c") { + if (altKey) { e.preventDefault(); copyIssueUrlToClipboard(); } - } else if (e.key.toLowerCase() === "c") { + } else if (keyPressed === "c") { e.preventDefault(); setIsIssueModalOpen(true); - } else if (e.key.toLowerCase() === "p") { - e.preventDefault(); - setIsProjectModalOpen(true); - } else if (e.key.toLowerCase() === "v") { - e.preventDefault(); - setIsCreateViewModalOpen(true); - } else if (e.key.toLowerCase() === "d") { - e.preventDefault(); - setIsCreateUpdatePageModalOpen(true); - } else if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "b") { + } else if ((ctrlKey || metaKey) && keyPressed === "b") { e.preventDefault(); toggleCollapsed(); - } else if (e.key.toLowerCase() === "h") { - e.preventDefault(); - setIsShortcutsModalOpen(true); - } else if (e.key.toLowerCase() === "q") { - e.preventDefault(); - setIsCreateCycleModalOpen(true); - } else if (e.key.toLowerCase() === "m") { - e.preventDefault(); - setIsCreateModuleModalOpen(true); - } else if (e.key === "Delete") { + } else if (key === "Delete") { e.preventDefault(); setIsBulkDeleteIssuesModalOpen(true); + } else if ( + singleShortcutKeys.includes(keyPressed) && + (ctrlKey || metaKey || altKey || shiftKey) + ) { + e.preventDefault(); + } else if (keyPressed === "p") { + setIsProjectModalOpen(true); + } else if (keyPressed === "v") { + setIsCreateViewModalOpen(true); + } else if (keyPressed === "d") { + setIsCreateUpdatePageModalOpen(true); + } else if (keyPressed === "h") { + setIsShortcutsModalOpen(true); + } else if (keyPressed === "q") { + setIsCreateCycleModalOpen(true); + } else if (keyPressed === "m") { + setIsCreateModuleModalOpen(true); } } },