Feat:新增搜索所有节点(包含被收起的节点)的配置;搜索默认改为搜索所有节点;

This commit is contained in:
街角小林 2024-02-26 18:19:47 +08:00
parent 403aae4b3d
commit 952472a977
3 changed files with 27 additions and 12 deletions

View File

@ -275,5 +275,7 @@ export const defaultOpt = {
customCreateNodePolygon: null, customCreateNodePolygon: null,
// 自定义转换节点连线路径的方法 // 自定义转换节点连线路径的方法
// 接收svg path字符串返回转换后的svg path字符串 // 接收svg path字符串返回转换后的svg path字符串
customTransformNodeLinePath: null customTransformNodeLinePath: null,
// 是否仅搜索当前渲染的节点,被收起的节点不会被搜索到
isOnlySearchCurrentRenderNodes: false
} }

View File

@ -1701,7 +1701,7 @@ class Render {
if (targetNode) { if (targetNode) {
targetNode.active() targetNode.active()
this.moveNodeToCenter(targetNode) this.moveNodeToCenter(targetNode)
callback() callback(targetNode)
} }
}) })
} }

View File

@ -4,6 +4,7 @@ import {
isUndef, isUndef,
replaceHtmlText replaceHtmlText
} from '../utils/index' } from '../utils/index'
import Node from '../core/render/node/Node'
// 搜索插件 // 搜索插件
class Search { class Search {
@ -84,8 +85,14 @@ class Search {
doSearch() { doSearch() {
this.matchNodeList = [] this.matchNodeList = []
this.currentIndex = -1 this.currentIndex = -1
bfsWalk(this.mindMap.renderer.root, node => { const { isOnlySearchCurrentRenderNodes } = this.mindMap.opt
let { richText, text } = node.getData() const tree = isOnlySearchCurrentRenderNodes
? this.mindMap.renderer.root
: this.mindMap.renderer.renderTree
bfsWalk(tree, node => {
let { richText, text } = isOnlySearchCurrentRenderNodes
? node.getData()
: node.data
if (richText) { if (richText) {
text = getTextFromHtml(text) text = getTextFromHtml(text)
} }
@ -103,16 +110,22 @@ class Search {
} else { } else {
this.currentIndex = 0 this.currentIndex = 0
} }
let currentNode = this.matchNodeList[this.currentIndex] const currentNode = this.matchNodeList[this.currentIndex]
this.notResetSearchText = true this.notResetSearchText = true
this.mindMap.execCommand('GO_TARGET_NODE', currentNode, () => { this.mindMap.execCommand(
this.notResetSearchText = false 'GO_TARGET_NODE',
callback() currentNode instanceof Node ? currentNode : currentNode.data.uid,
// 只读模式下节点无法激活,所以通过高亮的方式 node => {
if (this.mindMap.opt.readonly) { if (!(currentNode instanceof Node)) {
currentNode.highlight() this.matchNodeList[this.currentIndex] = node
}
callback()
// 只读模式下节点无法激活,所以通过高亮的方式
if (this.mindMap.opt.readonly) {
node.highlight()
}
} }
}) )
} }
// 替换当前节点 // 替换当前节点