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 => {