From 80727b759d15efaa515cc033467f6fe779c76659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Fri, 29 Mar 2024 18:02:02 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=97=B6=E5=85=A8=E9=83=A8=E6=9B=BF=E6=8D=A2=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/Search.js | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 7b5d69a4..8e7727ac 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -86,6 +86,7 @@ class Search { this.matchNodeList = [] this.currentIndex = -1 const { isOnlySearchCurrentRenderNodes } = this.mindMap.opt + // 如果要搜索收起来的节点,那么要遍历渲染树而不是节点树 const tree = isOnlySearchCurrentRenderNodes ? this.mindMap.renderer.root : this.mindMap.renderer.renderTree @@ -103,6 +104,11 @@ class Search { }) } + // 判断对象是否是节点实例 + isNodeInstance(node) { + return node instanceof Node + } + // 搜索下一个,定位到下一个匹配节点 searchNext(callback) { if (!this.isSearching || this.matchNodeList.length <= 0) return @@ -113,13 +119,12 @@ class Search { } const currentNode = this.matchNodeList[this.currentIndex] this.notResetSearchText = true - const uid = - currentNode instanceof Node - ? currentNode.getData('uid') - : currentNode.data.uid + const uid = this.isNodeInstance(currentNode) + ? currentNode.getData('uid') + : currentNode.data.uid const targetNode = this.mindMap.renderer.findNodeByUid(uid) this.mindMap.execCommand('GO_TARGET_NODE', uid, node => { - if (!(currentNode instanceof Node)) { + if (!this.isNodeInstance(currentNode)) { this.matchNodeList[this.currentIndex] = node } callback() @@ -173,15 +178,20 @@ class Search { return replaceText = String(replaceText) this.matchNodeList.forEach(node => { - let text = this.getReplacedText(node, this.searchText, replaceText) - this.mindMap.renderer.setNodeDataRender( - node, - { - text, - resetRichText: !!node.getData('richText') - }, - true - ) + const text = this.getReplacedText(node, this.searchText, replaceText) + if (this.isNodeInstance(node)) { + this.mindMap.renderer.setNodeDataRender( + node, + { + text, + resetRichText: !!node.getData('richText') + }, + true + ) + } else { + node.data.text = text + node.data.resetRichText = !!node.data.richText + } }) this.mindMap.render() this.mindMap.command.addHistory() @@ -190,7 +200,9 @@ class Search { // 获取某个节点替换后的文本 getReplacedText(node, searchText, replaceText) { - let { richText, text } = node.getData() + let { richText, text } = this.isNodeInstance(node) + ? node.getData() + : node.data if (richText) { return replaceHtmlText(text, searchText, replaceText) } else {