mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Feat:增加beforeShortcutRun实例化选项用于拦截快捷键操作
This commit is contained in:
parent
1085473463
commit
2f91ea7199
@ -288,5 +288,8 @@ export const defaultOpt = {
|
||||
data: 1.当type=createOrUpdate时,代表被创建或被更新的节点数据,即将同步到其他客户端,所以你可以修改该数据;2.当type=delete时,代表被删除的节点数据
|
||||
}
|
||||
*/
|
||||
beforeCooperateUpdate: null
|
||||
beforeCooperateUpdate: null,
|
||||
// 快捷键操作即将执行前的生命周期函数,返回true可以阻止操作执行
|
||||
// 函数接收两个参数:key(快捷键)、activeNodeList(当前激活的节点列表)
|
||||
beforeShortcutRun: null
|
||||
}
|
||||
|
||||
@ -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()
|
||||
})
|
||||
|
||||
@ -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 => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user