From 2f91ea7199b17f04818713cf1cc30710d6a0cc96 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, 13 Mar 2024 15:31:50 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=A2=9E=E5=8A=A0beforeShortcutRu?= =?UTF-8?q?n=E5=AE=9E=E4=BE=8B=E5=8C=96=E9=80=89=E9=A1=B9=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=8B=A6=E6=88=AA=E5=BF=AB=E6=8D=B7=E9=94=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/constants/defaultOptions.js | 5 ++++- simple-mind-map/src/core/command/KeyCommand.js | 7 ++++++- web/src/pages/Edit/components/Edit.vue | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index e192b262..da96e73f 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -288,5 +288,8 @@ export const defaultOpt = { data: 1.当type=createOrUpdate时,代表被创建或被更新的节点数据,即将同步到其他客户端,所以你可以修改该数据;2.当type=delete时,代表被删除的节点数据 } */ - beforeCooperateUpdate: null + beforeCooperateUpdate: null, + // 快捷键操作即将执行前的生命周期函数,返回true可以阻止操作执行 + // 函数接收两个参数:key(快捷键)、activeNodeList(当前激活的节点列表) + beforeShortcutRun: null } diff --git a/simple-mind-map/src/core/command/KeyCommand.js b/simple-mind-map/src/core/command/KeyCommand.js index 8474e84b..95e4440d 100644 --- a/simple-mind-map/src/core/command/KeyCommand.js +++ b/simple-mind-map/src/core/command/KeyCommand.js @@ -67,9 +67,10 @@ export default class KeyCommand { // 按键事件 onKeydown(e) { + const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } = this.mindMap.opt if ( this.isPause || - (this.mindMap.opt.enableShortcutOnlyWhenMouseInSvg && !this.isInSvg) + (enableShortcutOnlyWhenMouseInSvg && !this.isInSvg) ) { return } @@ -80,6 +81,10 @@ export default class KeyCommand { e.stopPropagation() e.preventDefault() } + if (typeof beforeShortcutRun === 'function') { + const isStop = beforeShortcutRun(key, [...this.mindMap.renderer.activeNodeList]) + if (isStop) return + } this.shortcutMap[key].forEach(fn => { fn() }) diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 89a3abef..70d49932 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -349,6 +349,13 @@ export default { break } } + // beforeShortcutRun: (key, activeNodeList) => { + // console.log(key, activeNodeList) + // // 阻止删除快捷键行为 + // if (key === 'Backspace') { + // return true + // } + // } // handleNodePasteImg: img => { // console.log(img) // return new Promise(resolve => {