Feat:KeyCommand类:1.如果当前存在缓存数据,save方法不允许添加新缓存;2.缓存数据为空,restore方法不执行
This commit is contained in:
parent
eb2e577219
commit
3c63d94d9c
@ -27,12 +27,20 @@ export default class KeyCommand {
|
|||||||
|
|
||||||
// 保存当前注册的快捷键数据,然后清空快捷键数据
|
// 保存当前注册的快捷键数据,然后清空快捷键数据
|
||||||
save() {
|
save() {
|
||||||
|
// 当前已经存在缓存数据了,那么直接返回
|
||||||
|
if (Object.keys(this.shortcutMapCache).length > 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
this.shortcutMapCache = this.shortcutMap
|
this.shortcutMapCache = this.shortcutMap
|
||||||
this.shortcutMap = {}
|
this.shortcutMap = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 恢复保存的快捷键数据,然后清空缓存数据
|
// 恢复保存的快捷键数据,然后清空缓存数据
|
||||||
restore() {
|
restore() {
|
||||||
|
// 当前不存在缓存数据,那么直接返回
|
||||||
|
if (Object.keys(this.shortcutMapCache).length <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
this.shortcutMap = this.shortcutMapCache
|
this.shortcutMap = this.shortcutMapCache
|
||||||
this.shortcutMapCache = {}
|
this.shortcutMapCache = {}
|
||||||
}
|
}
|
||||||
@ -67,11 +75,9 @@ export default class KeyCommand {
|
|||||||
|
|
||||||
// 按键事件
|
// 按键事件
|
||||||
onKeydown(e) {
|
onKeydown(e) {
|
||||||
const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } = this.mindMap.opt
|
const { enableShortcutOnlyWhenMouseInSvg, beforeShortcutRun } =
|
||||||
if (
|
this.mindMap.opt
|
||||||
this.isPause ||
|
if (this.isPause || (enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)) {
|
||||||
(enableShortcutOnlyWhenMouseInSvg && !this.isInSvg)
|
|
||||||
) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Object.keys(this.shortcutMap).forEach(key => {
|
Object.keys(this.shortcutMap).forEach(key => {
|
||||||
@ -82,7 +88,9 @@ export default class KeyCommand {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
if (typeof beforeShortcutRun === 'function') {
|
if (typeof beforeShortcutRun === 'function') {
|
||||||
const isStop = beforeShortcutRun(key, [...this.mindMap.renderer.activeNodeList])
|
const isStop = beforeShortcutRun(key, [
|
||||||
|
...this.mindMap.renderer.activeNodeList
|
||||||
|
])
|
||||||
if (isStop) return
|
if (isStop) return
|
||||||
}
|
}
|
||||||
this.shortcutMap[key].forEach(fn => {
|
this.shortcutMap[key].forEach(fn => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user