From fcc2ee8baab02b8688cc360b421f9257d9ab529b Mon Sep 17 00:00:00 2001 From: baiqi Date: Fri, 20 Sep 2024 14:10:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=84=91=E5=9B=BE):=20=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E9=94=AE=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046501 --user=白奇 可以在不聚焦脑图节点的状态下,使用快捷键保存脑图 https://www.tapd.cn/55049933/s/1582304 --- .../ms-minder-editor/hooks/useShortCut.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/pure/ms-minder-editor/hooks/useShortCut.ts b/frontend/src/components/pure/ms-minder-editor/hooks/useShortCut.ts index dbff8fb0f8..b51a856db3 100644 --- a/frontend/src/components/pure/ms-minder-editor/hooks/useShortCut.ts +++ b/frontend/src/components/pure/ms-minder-editor/hooks/useShortCut.ts @@ -51,7 +51,6 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati // z: 'undo', // 撤销 TODO:暂时不上撤销和重做 // y: 'redo', // 重做 enter: 'enter', // 进入节点 - s: 'save', // 保存 }; // 定义单键事件 const singleShortcuts: { [key: string]: ShortcutKey } = { @@ -97,9 +96,32 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati } }; + const handleShortcutSave = (event: KeyboardEvent) => { + const { editor } = window; + const { fsm } = editor; + const state = fsm.state(); + switch (state) { + case 'input': { + // 输入状态下不响应快捷键 + return; + } + default: + } + const key = event.key.toLowerCase(); + const isCtrlOrCmd = event.ctrlKey || event.metaKey; + + if (isCtrlOrCmd && key === 's') { + // 执行快捷键保存事件 + if (shortcuts.save) { + shortcuts.save(event); + } + } + }; + onMounted(() => { const minderContainer = document.querySelector('.ms-minder-container'); if (minderContainer) { + window.addEventListener('keydown', handleShortcutSave); minderContainer.addEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent)); minderContainer.addEventListener('copy', (e) => minderCopy(e as ClipboardEvent)); minderContainer.addEventListener('cut', (e) => minderCut(e as ClipboardEvent)); @@ -110,6 +132,7 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati function unbindShortcuts() { const minderContainer = document.querySelector('.ms-minder-container'); if (minderContainer) { + window.removeEventListener('keydown', handleShortcutSave); minderContainer.removeEventListener('keydown', (e) => handleKeyDown(e as KeyboardEvent)); minderContainer.removeEventListener('copy', (e) => minderCopy(e as ClipboardEvent)); minderContainer.removeEventListener('cut', (e) => minderCut(e as ClipboardEvent));