From 983e55bd1dfa985c43e1ef5add7a243e9b186c0b Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Tue, 4 Apr 2023 22:53:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=E5=8F=AA=E6=9C=89=E5=BD=93?= =?UTF-8?q?=E9=BC=A0=E6=A0=87=E5=9C=A8=E7=94=BB=E5=B8=83=E5=86=85=E6=89=8D?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/Event.js | 16 ++++++++++++++++ simple-mind-map/src/KeyCommand.js | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/simple-mind-map/src/Event.js b/simple-mind-map/src/Event.js index 39374272..917f51b8 100644 --- a/simple-mind-map/src/Event.js +++ b/simple-mind-map/src/Event.js @@ -35,6 +35,8 @@ class Event extends EventEmitter { this.onContextmenu = this.onContextmenu.bind(this) this.onSvgMousedown = this.onSvgMousedown.bind(this) this.onKeyup = this.onKeyup.bind(this) + this.onMouseenter = this.onMouseenter.bind(this) + this.onMouseleave = this.onMouseleave.bind(this) } // 绑定事件 @@ -46,6 +48,8 @@ class Event extends EventEmitter { window.addEventListener('mouseup', this.onMouseup) this.mindMap.el.addEventListener('wheel', this.onMousewheel) this.mindMap.svg.on('contextmenu', this.onContextmenu) + this.mindMap.svg.on('mouseenter', this.onMouseenter) + this.mindMap.svg.on('mouseleave', this.onMouseleave) window.addEventListener('keyup', this.onKeyup) } @@ -57,6 +61,8 @@ class Event extends EventEmitter { window.removeEventListener('mouseup', this.onMouseup) this.mindMap.el.removeEventListener('wheel', this.onMousewheel) this.mindMap.svg.off('contextmenu', this.onContextmenu) + this.mindMap.svg.off('mouseenter', this.onMouseenter) + this.mindMap.svg.off('mouseleave', this.onMouseleave) window.removeEventListener('keyup', this.onKeyup) } @@ -130,6 +136,16 @@ class Event extends EventEmitter { onKeyup(e) { this.emit('keyup', e) } + + // 进入 + onMouseenter(e) { + this.emit('svg_mouseenter', e) + } + + // 离开 + onMouseleave(e) { + this.emit('svg_mouseleave', e) + } } export default Event diff --git a/simple-mind-map/src/KeyCommand.js b/simple-mind-map/src/KeyCommand.js index 79aad141..5405ee02 100644 --- a/simple-mind-map/src/KeyCommand.js +++ b/simple-mind-map/src/KeyCommand.js @@ -10,6 +10,7 @@ export default class KeyCommand { } this.shortcutMapCache = {} this.isPause = false + this.isInSvg = false this.bindEvent() } @@ -37,8 +38,21 @@ export default class KeyCommand { // 绑定事件 bindEvent() { + // 只有当鼠标在画布内才响应快捷键 + this.mindMap.on('svg_mouseenter', () => { + this.isInSvg = true + }) + this.mindMap.on('svg_mouseleave', () => { + if (this.mindMap.richText && this.mindMap.richText.showTextEdit) { + return + } + if (this.mindMap.renderer.textEdit.showTextEdit) { + return + } + this.isInSvg = false + }) window.addEventListener('keydown', e => { - if (this.isPause) { + if (this.isPause || !this.isInSvg) { return } Object.keys(this.shortcutMap).forEach(key => {