Feat:增加beforeShortcutRun实例化选项用于拦截快捷键操作

This commit is contained in:
街角小林 2024-03-13 15:31:50 +08:00
parent 1085473463
commit 2f91ea7199
3 changed files with 17 additions and 2 deletions

View File

@ -288,5 +288,8 @@ export const defaultOpt = {
data: 1.当type=createOrUpdate时代表被创建或被更新的节点数据即将同步到其他客户端所以你可以修改该数据2.当type=delete时代表被删除的节点数据
}
*/
beforeCooperateUpdate: null
beforeCooperateUpdate: null,
// 快捷键操作即将执行前的生命周期函数返回true可以阻止操作执行
// 函数接收两个参数key快捷键、activeNodeList当前激活的节点列表
beforeShortcutRun: null
}

View File

@ -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()
})

View File

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