From 952472a977726495a10e555db13c6ce22da89401 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: Mon, 26 Feb 2024 18:19:47 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=89=80=E6=9C=89=E8=8A=82=E7=82=B9=EF=BC=88=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E8=A2=AB=E6=94=B6=E8=B5=B7=E7=9A=84=E8=8A=82=E7=82=B9?= =?UTF-8?q?=EF=BC=89=E7=9A=84=E9=85=8D=E7=BD=AE=EF=BC=9B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=94=B9=E4=B8=BA=E6=90=9C=E7=B4=A2=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=8A=82=E7=82=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/constants/defaultOptions.js | 4 ++- simple-mind-map/src/core/render/Render.js | 2 +- simple-mind-map/src/plugins/Search.js | 33 +++++++++++++------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 0d339e82..28050da3 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -275,5 +275,7 @@ export const defaultOpt = { customCreateNodePolygon: null, // 自定义转换节点连线路径的方法 // 接收svg path字符串,返回转换后的svg path字符串 - customTransformNodeLinePath: null + customTransformNodeLinePath: null, + // 是否仅搜索当前渲染的节点,被收起的节点不会被搜索到 + isOnlySearchCurrentRenderNodes: false } diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 13d290d7..f0b35be6 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -1701,7 +1701,7 @@ class Render { if (targetNode) { targetNode.active() this.moveNodeToCenter(targetNode) - callback() + callback(targetNode) } }) } diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 8d14b5f7..de2ca073 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -4,6 +4,7 @@ import { isUndef, replaceHtmlText } from '../utils/index' +import Node from '../core/render/node/Node' // 搜索插件 class Search { @@ -84,8 +85,14 @@ class Search { doSearch() { this.matchNodeList = [] this.currentIndex = -1 - bfsWalk(this.mindMap.renderer.root, node => { - let { richText, text } = node.getData() + const { isOnlySearchCurrentRenderNodes } = this.mindMap.opt + const tree = isOnlySearchCurrentRenderNodes + ? this.mindMap.renderer.root + : this.mindMap.renderer.renderTree + bfsWalk(tree, node => { + let { richText, text } = isOnlySearchCurrentRenderNodes + ? node.getData() + : node.data if (richText) { text = getTextFromHtml(text) } @@ -103,16 +110,22 @@ class Search { } else { this.currentIndex = 0 } - let currentNode = this.matchNodeList[this.currentIndex] + const currentNode = this.matchNodeList[this.currentIndex] this.notResetSearchText = true - this.mindMap.execCommand('GO_TARGET_NODE', currentNode, () => { - this.notResetSearchText = false - callback() - // 只读模式下节点无法激活,所以通过高亮的方式 - if (this.mindMap.opt.readonly) { - currentNode.highlight() + this.mindMap.execCommand( + 'GO_TARGET_NODE', + currentNode instanceof Node ? currentNode : currentNode.data.uid, + node => { + if (!(currentNode instanceof Node)) { + this.matchNodeList[this.currentIndex] = node + } + callback() + // 只读模式下节点无法激活,所以通过高亮的方式 + if (this.mindMap.opt.readonly) { + node.highlight() + } } - }) + ) } // 替换当前节点