From 83c9d16d2b2678ae0445206da01d71ba5380cff4 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: Fri, 23 Aug 2024 14:56:13 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E6=90=9C=E7=B4=A2=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=A2=9E=E5=8A=A0=E8=B7=B3=E8=BD=AC=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E7=B4=A2=E5=BC=95=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/Search.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index a5bf129e..46bcc96b 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -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 (