From 3c63d94d9c4742c41cbe5b89a6e90fc31fd02448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 21 Aug 2024 09:02:30 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9AKeyCommand=E7=B1=BB=EF=BC=9A1.?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E5=BD=93=E5=89=8D=E5=AD=98=E5=9C=A8=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=95=B0=E6=8D=AE=EF=BC=8Csave=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=EF=BC=9B2.=E7=BC=93=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=EF=BC=8Crestore=E6=96=B9=E6=B3=95=E4=B8=8D?= =?UTF-8?q?=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/command/KeyCommand.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/simple-mind-map/src/core/command/KeyCommand.js b/simple-mind-map/src/core/command/KeyCommand.js index 95e4440d..13c7783d 100644 --- a/simple-mind-map/src/core/command/KeyCommand.js +++ b/simple-mind-map/src/core/command/KeyCommand.js @@ -27,12 +27,20 @@ export default class KeyCommand { // 保存当前注册的快捷键数据,然后清空快捷键数据 save() { + // 当前已经存在缓存数据了,那么直接返回 + if (Object.keys(this.shortcutMapCache).length > 0) { + return + } this.shortcutMapCache = this.shortcutMap this.shortcutMap = {} } // 恢复保存的快捷键数据,然后清空缓存数据 restore() { + // 当前不存在缓存数据,那么直接返回 + if (Object.keys(this.shortcutMapCache).length <= 0) { + return + } this.shortcutMap = this.shortcutMapCache this.shortcutMapCache = {} } @@ -67,11 +75,9 @@ export default class KeyCommand { // 按键事件 onKeydown(e) { - const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } = this.mindMap.opt - if ( - this.isPause || - (enableShortcutOnlyWhenMouseInSvg && !this.isInSvg) - ) { + const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } = + this.mindMap.opt + if (this.isPause || (enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)) { return } Object.keys(this.shortcutMap).forEach(key => { @@ -82,7 +88,9 @@ export default class KeyCommand { e.preventDefault() } if (typeof beforeShortcutRun === 'function') { - const isStop = beforeShortcutRun(key, [...this.mindMap.renderer.activeNodeList]) + const isStop = beforeShortcutRun(key, [ + ...this.mindMap.renderer.activeNodeList + ]) if (isStop) return } this.shortcutMap[key].forEach(fn => {