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时,代表被删除的节点数据
|
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) {
|
onKeydown(e) {
|
||||||
|
const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } = this.mindMap.opt
|
||||||
if (
|
if (
|
||||||
this.isPause ||
|
this.isPause ||
|
||||||
(this.mindMap.opt.enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)
|
(enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -80,6 +81,10 @@ export default class KeyCommand {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
|
if (typeof beforeShortcutRun === 'function') {
|
||||||
|
const isStop = beforeShortcutRun(key, [...this.mindMap.renderer.activeNodeList])
|
||||||
|
if (isStop) return
|
||||||
|
}
|
||||||
this.shortcutMap[key].forEach(fn => {
|
this.shortcutMap[key].forEach(fn => {
|
||||||
fn()
|
fn()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -349,6 +349,13 @@ export default {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// beforeShortcutRun: (key, activeNodeList) => {
|
||||||
|
// console.log(key, activeNodeList)
|
||||||
|
// // 阻止删除快捷键行为
|
||||||
|
// if (key === 'Backspace') {
|
||||||
|
// return true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
// handleNodePasteImg: img => {
|
// handleNodePasteImg: img => {
|
||||||
// console.log(img)
|
// console.log(img)
|
||||||
// return new Promise(resolve => {
|
// return new Promise(resolve => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user