Feat:搜索插件增加跳转指定搜索结果索引节点的方法

This commit is contained in:
街角小林
2024-08-23 14:56:13 +08:00
parent b8765bdd99
commit 83c9d16d2b

View File

@@ -156,13 +156,22 @@ class Search {
return node instanceof MindMapNode
}
// 搜索下一个,定位到下一个匹配节点
searchNext(callback) {
// 搜索下一个或指定索引,定位到下一个匹配节点
searchNext(callback, index) {
if (!this.isSearching || this.matchNodeList.length <= 0) return
if (this.currentIndex < this.matchNodeList.length - 1) {
this.currentIndex++
if (
index !== undefined &&
Number.isInteger(index) &&
index >= 0 &&
index < this.matchNodeList.length
) {
this.currentIndex = index
} else {
this.currentIndex = 0
if (this.currentIndex < this.matchNodeList.length - 1) {
this.currentIndex++
} else {
this.currentIndex = 0
}
}
const { readonly } = this.mindMap.opt
// 只读模式下需要激活之前节点的高亮
@@ -196,6 +205,11 @@ class Search {
})
}
// 定位到指定搜索结果索引的节点
jump(index, callback) {
this.searchNext(callback, index)
}
// 替换当前节点
replace(replaceText, jumpNext = false) {
if (