diff --git a/simple-mind-map/src/constants/constant.js b/simple-mind-map/src/constants/constant.js index 02236a4e..32fc5c0b 100644 --- a/simple-mind-map/src/constants/constant.js +++ b/simple-mind-map/src/constants/constant.js @@ -346,7 +346,7 @@ export const cssContent = ` display: block; } - .smm-node.active .smm-hover-node{ + .smm-node.active .smm-hover-node, .smm-node-highlight .smm-hover-node{ display: block; opacity: 1; stroke-width: 2; diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 902af1bc..5ac1017f 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -1052,6 +1052,16 @@ class Node { height: height * scaleY } } + + // 高亮节点 + highlight() { + if (this.group) this.group.addClass('smm-node-highlight') + } + + // 取消高亮节点 + closeHighlight() { + if (this.group) this.group.removeClass('smm-node-highlight') + } } export default Node diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 64c763dd..8d14b5f7 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -69,14 +69,14 @@ class Search { // 结束搜索 endSearch() { if (!this.isSearching) return + if (this.mindMap.opt.readonly && this.matchNodeList[this.currentIndex]) { + this.matchNodeList[this.currentIndex].closeHighlight() + } this.searchText = '' this.matchNodeList = [] this.currentIndex = -1 this.notResetSearchText = false this.isSearching = false - if (this.mindMap.opt.readonly) { - this.mindMap.renderer.closeHighlightNode() - } this.emitEvent() } @@ -110,7 +110,7 @@ class Search { callback() // 只读模式下节点无法激活,所以通过高亮的方式 if (this.mindMap.opt.readonly) { - this.mindMap.renderer.highlightNode(currentNode) + currentNode.highlight() } }) }