Fix:修复节点文本编辑状态中鼠标选择文本时移除编辑框,文字选中状态会丢失的问题

This commit is contained in:
街角小林 2023-12-25 18:09:25 +08:00
parent bac174c8df
commit 9db988e3ec
2 changed files with 14 additions and 0 deletions

View File

@ -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)

View File

@ -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()