about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/state/shell/composer/useComposerKeyboardShortcut.tsx17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/state/shell/composer/useComposerKeyboardShortcut.tsx b/src/state/shell/composer/useComposerKeyboardShortcut.tsx
index f46062185..0cdc6c754 100644
--- a/src/state/shell/composer/useComposerKeyboardShortcut.tsx
+++ b/src/state/shell/composer/useComposerKeyboardShortcut.tsx
@@ -1,5 +1,9 @@
 import React from 'react'
 
+import {useDialogStateContext} from '#/state/dialogs'
+import {useLightbox} from '#/state/lightbox'
+import {useModals} from '#/state/modals'
+import {useIsDrawerOpen} from '#/state/shell/drawer-open'
 import {useComposerControls} from './'
 
 /**
@@ -35,15 +39,26 @@ function shouldIgnore(event: KeyboardEvent) {
 
 export function useComposerKeyboardShortcut() {
   const {openComposer} = useComposerControls()
+  const {openDialogs} = useDialogStateContext()
+  const {isModalActive} = useModals()
+  const {activeLightbox} = useLightbox()
+  const isDrawerOpen = useIsDrawerOpen()
 
   React.useEffect(() => {
     function handler(event: KeyboardEvent) {
       if (shouldIgnore(event)) return
+      if (
+        openDialogs.current.size > 0 ||
+        isModalActive ||
+        activeLightbox ||
+        isDrawerOpen
+      )
+        return
       if (event.key === 'n' || event.key === 'N') {
         openComposer({})
       }
     }
     document.addEventListener('keydown', handler)
     return () => document.removeEventListener('keydown', handler)
-  }, [openComposer])
+  }, [openComposer, isModalActive, openDialogs, activeLightbox, isDrawerOpen])
 }