diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 657414e7..0a25d8da 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -234,7 +234,7 @@ class MindMap { // 设置主题 setTheme(theme, notRender = false) { - this.renderer.clearAllActive() + this.execCommand('CLEAR_ACTIVE_NODE') this.opt.theme = theme if (!notRender) { this.render(null, CONSTANTS.CHANGE_THEME) @@ -381,7 +381,7 @@ class MindMap { this.opt.readonly = mode === CONSTANTS.MODE.READONLY if (this.opt.readonly) { // 取消当前激活的元素 - this.renderer.clearAllActive() + this.execCommand('CLEAR_ACTIVE_NODE') } this.emit('mode_change', mode) } diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 7d5507c8..4cea86e7 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -202,8 +202,8 @@ class Render { this.setNodeActive = this.setNodeActive.bind(this) this.mindMap.command.add('SET_NODE_ACTIVE', this.setNodeActive) // 清除所有激活节点 - this.clearAllActive = this.clearAllActive.bind(this) - this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearAllActive) + this.clearActiveNode = this.clearActiveNode.bind(this) + this.mindMap.command.add('CLEAR_ACTIVE_NODE', this.clearActiveNode) // 切换节点是否展开 this.setNodeExpand = this.setNodeExpand.bind(this) this.mindMap.command.add('SET_NODE_EXPAND', this.setNodeExpand) @@ -400,6 +400,15 @@ class Render { this.mindMap.emit('node_active', null, [...this.activeNodeList]) } + // 清除当前所有激活节点,并会触发事件 + clearActiveNode() { + if (this.activeNodeList.length <= 0) { + return + } + this.clearActive() + this.mindMap.emit('node_active', null, []) + } + // 清除当前激活的节点 clearActive() { this.activeNodeList.forEach(item => { @@ -408,15 +417,6 @@ class Render { this.activeNodeList = [] } - // 清除当前所有激活节点,并会触发事件 - clearAllActive() { - if (this.activeNodeList.length <= 0) { - return - } - this.clearActive() - this.mindMap.emit('node_active', null, []) - } - // 添加节点到激活列表里 addActiveNode(node) { let index = this.findActiveNodeIndex(node) @@ -467,7 +467,7 @@ class Render { // 回退 back(step) { - this.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') let data = this.mindMap.command.back(step) if (data) { this.renderTree = data @@ -477,7 +477,7 @@ class Render { // 前进 forward(step) { - this.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') let data = this.mindMap.command.forward(step) if (data) { this.renderTree = data diff --git a/simple-mind-map/src/plugins/Drag.js b/simple-mind-map/src/plugins/Drag.js index a8162ab4..2b9ce554 100644 --- a/simple-mind-map/src/plugins/Drag.js +++ b/simple-mind-map/src/plugins/Drag.js @@ -222,7 +222,7 @@ class Drag extends Base { // 创建克隆节点 this.createCloneNode() // 清除当前所有激活的节点 - this.mindMap.renderer.clearAllActive() + this.mindMap.execCommand('CLEAR_ACTIVE_NODE') } }