From c8fcfa21200a3a2185591a03c1b1abb8d8e9072c Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 24 Apr 2022 14:50:06 +0800 Subject: [PATCH] fix: reset expanded nodes on search --- src/utils/VisibleNodesGenerator/index.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/utils/VisibleNodesGenerator/index.ts b/src/utils/VisibleNodesGenerator/index.ts index 1e34032..575d236 100644 --- a/src/utils/VisibleNodesGenerator/index.ts +++ b/src/utils/VisibleNodesGenerator/index.ts @@ -251,13 +251,10 @@ class FlattenLayer extends CompressLayer { } barelySetExpand = (node: TreeNode, expand: boolean) => { - if (expand) { - if (node.type === 'tree') { - // expanding non-tree node could cause unexpected UX - this.expandedNodes.add(node.path) - } - } else { - this.expandedNodes.delete(node.path) + // expanding non-tree node could cause unexpected UX + if (node.type === 'tree') { + if (expand) this.expandedNodes.add(node.path) + else this.expandedNodes.delete(node.path) } } @@ -309,12 +306,13 @@ class FlattenLayer extends CompressLayer { searchParams: Pick | null, restoreExpandedFolders?: boolean, ) => { - // backup expansion before search if (searchParams) { if (!this.isSearching) { + // backup expansion when start search this.backupExpandedNodes.clear() this.expandedNodes.forEach(path => this.backupExpandedNodes.add(path)) } + this.expandedNodes.clear() // Reset expansion on every search, ensure cleanest search result expansion this.shake({ matchNode: searchParams.matchNode, onChildMatch: node => this.$setExpand(node, true),