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,
// 自定义转换节点连线路径的方法
// 接收svg path字符串返回转换后的svg path字符串
customTransformNodeLinePath: null
customTransformNodeLinePath: null,
// 是否仅搜索当前渲染的节点,被收起的节点不会被搜索到
isOnlySearchCurrentRenderNodes: false
}

View File

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

View File

@ -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()
}
}
})
)
}
// 替换当前节点