diff --git a/simple-mind-map/src/plugins/Select.js b/simple-mind-map/src/plugins/Select.js index e3fba7bc..329b4dc1 100644 --- a/simple-mind-map/src/plugins/Select.js +++ b/simple-mind-map/src/plugins/Select.js @@ -12,6 +12,7 @@ class Select { this.mouseMoveX = 0 this.mouseMoveY = 0 this.isSelecting = false + this.cacheActiveList = [] this.bindEvent() } @@ -31,6 +32,7 @@ class Select { } e.preventDefault() this.isMousedown = true + this.cacheActiveList = [...this.mindMap.renderer.activeNodeList] let { x, y } = this.mindMap.toPos(e.clientX, e.clientY) this.mouseDownX = x this.mouseDownY = y @@ -62,13 +64,10 @@ class Select { if (!this.isMousedown) { return } - this.mindMap.emit( - 'node_active', - null, - this.mindMap.renderer.activeNodeList - ) + this.checkTriggerNodeActiveEvent() clearTimeout(this.autoMoveTimer) this.isMousedown = false + this.cacheActiveList = [] if (this.rect) this.rect.remove() this.rect = null setTimeout(() => { @@ -77,6 +76,30 @@ class Select { }) } + // 如果激活节点改变了,那么触发事件 + checkTriggerNodeActiveEvent() { + let isNumChange = this.cacheActiveList.length !== this.mindMap.renderer.activeNodeList.length + let isNodeChange = false + if (!isNumChange) { + for(let i = 0; i < this.cacheActiveList.length; i++) { + let cur = this.cacheActiveList[i] + if (!this.mindMap.renderer.activeNodeList.find((item) => { + return item.nodeData.data.uid === cur.nodeData.data.uid + })){ + isNodeChange = true + break + } + } + } + if (isNumChange || isNodeChange) { + this.mindMap.emit( + 'node_active', + null, + this.mindMap.renderer.activeNodeList + ) + } + } + // 鼠标移动事件 onMove(x, y) { this.isSelecting = true