Skip to content

Commit

Permalink
Feat:新增搜索所有节点(包含被收起的节点)的配置;搜索默认改为搜索所有节点;
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglin2 committed Feb 26, 2024
1 parent 403aae4 commit 952472a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion simple-mind-map/src/constants/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,7 @@ export const defaultOpt = {
customCreateNodePolygon: null,
// 自定义转换节点连线路径的方法
// 接收svg path字符串,返回转换后的svg path字符串
customTransformNodeLinePath: null
customTransformNodeLinePath: null,
// 是否仅搜索当前渲染的节点,被收起的节点不会被搜索到
isOnlySearchCurrentRenderNodes: false
}
2 changes: 1 addition & 1 deletion simple-mind-map/src/core/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ class Render {
if (targetNode) {
targetNode.active()
this.moveNodeToCenter(targetNode)
callback()
callback(targetNode)
}
})
}
Expand Down
33 changes: 23 additions & 10 deletions simple-mind-map/src/plugins/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isUndef,
replaceHtmlText
} from '../utils/index'
import Node from '../core/render/node/Node'

// 搜索插件
class Search {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
}
}
})
)
}

// 替换当前节点
Expand Down

0 comments on commit 952472a

Please sign in to comment.