diff --git a/simple-mind-map/src/core/event/Event.js b/simple-mind-map/src/core/event/Event.js index bccc2b36..cb22c5a6 100644 --- a/simple-mind-map/src/core/event/Event.js +++ b/simple-mind-map/src/core/event/Event.js @@ -29,6 +29,7 @@ class Event extends EventEmitter { // 绑定函数上下文 bindFn() { + this.onBodyMousedown = this.onBodyMousedown.bind(this) this.onBodyClick = this.onBodyClick.bind(this) this.onDrawClick = this.onDrawClick.bind(this) this.onMousedown = this.onMousedown.bind(this) @@ -45,6 +46,7 @@ class Event extends EventEmitter { // 绑定事件 bind() { + document.body.addEventListener('mousedown', this.onBodyMousedown) document.body.addEventListener('click', this.onBodyClick) this.mindMap.svg.on('click', this.onDrawClick) this.mindMap.el.addEventListener('mousedown', this.onMousedown) @@ -61,6 +63,7 @@ class Event extends EventEmitter { // 解绑事件 unbind() { + document.body.removeEventListener('mousedown', this.onBodyMousedown) document.body.removeEventListener('click', this.onBodyClick) this.mindMap.svg.off('click', this.onDrawClick) this.mindMap.el.removeEventListener('mousedown', this.onMousedown) @@ -79,6 +82,11 @@ class Event extends EventEmitter { this.emit('draw_click', e) } + // 页面的鼠标按下事件 + onBodyMousedown(e) { + this.emit('body_mousedown', e) + } + // 页面的单击事件 onBodyClick(e) { this.emit('body_click', e) diff --git a/simple-mind-map/src/core/render/TextEdit.js b/simple-mind-map/src/core/render/TextEdit.js index 7fc1b1dd..620ba85a 100644 --- a/simple-mind-map/src/core/render/TextEdit.js +++ b/simple-mind-map/src/core/render/TextEdit.js @@ -21,6 +21,7 @@ export default class TextEdit { this.showTextEdit = false // 如果编辑过程中缩放画布了,那么缓存当前编辑的内容 this.cacheEditingText = '' + this.hasBodyMousedown = false this.bindEvent() } @@ -38,7 +39,12 @@ export default class TextEdit { // 隐藏文本编辑框 this.hideEditTextBox() }) + this.mindMap.on('body_mousedown', () => { + this.hasBodyMousedown = true + }) this.mindMap.on('body_click', () => { + if (!this.hasBodyMousedown) return + this.hasBodyMousedown = false // 隐藏文本编辑框 if (this.mindMap.opt.isEndNodeTextEditOnClickOuter) { this.hideEditTextBox()