Skip to content

Commit 12f3965

Browse files
duowbhyoban
andauthored
fix: ShortcutMode cannot be closed using shortcuts keys (#708)
Co-authored-by: Stephen Zhou <hi@hyoban.cc>
1 parent f1ce5df commit 12f3965

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

apps/renderer/src/components/ui/modal/stacked/hooks.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ export const useModalStack = (options?: ModalStackOptions) => {
6464
}
6565
}
6666
const actions = {
67+
getTopModalStack() {
68+
return jotaiStore.get(modalStackAtom)[0]
69+
},
70+
getModalStackById(id: string) {
71+
return jotaiStore.get(modalStackAtom).find((item) => item.id === id)
72+
},
6773
dismiss(id: string) {
6874
jotaiStore.set(modalStackAtom, (p) => p.filter((item) => item.id !== id))
6975
},

apps/renderer/src/modules/modal/shortcuts.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,26 @@ const ShortcutModalContent = () => {
8181
}
8282

8383
export const useShortcutsModal = () => {
84-
const { present } = useModalStack()
84+
const { present, dismiss, getModalStackById } = useModalStack()
85+
const id = "shortcuts"
8586

86-
return useCallback(() => {
87+
const showShortcutsModal = useCallback(() => {
8788
present({
8889
title: "Shortcuts",
90+
id,
8991
overlay: false,
90-
id: "shortcuts",
9192
content: () => <ShortcutModalContent />,
9293
CustomModalComponent: PlainModal,
9394
clickOutsideToDismiss: true,
9495
})
9596
}, [present])
97+
98+
return useCallback(() => {
99+
const shortcutsModal = getModalStackById(id)
100+
if (shortcutsModal && shortcutsModal.modal) {
101+
dismiss(id)
102+
return
103+
}
104+
showShortcutsModal()
105+
}, [dismiss, getModalStackById, showShortcutsModal])
96106
}

0 commit comments

Comments
 (0)