From dbdc3828ac6932dee42541db40b71dbd49510135 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 20 Mar 2022 22:41:28 +0800 Subject: [PATCH] fix: prevent resetting node state when toggle search mode but search input is empty fix #217 --- src/components/SearchBar.tsx | 3 ++- src/utils/VisibleNodesGenerator.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx index f3d435c..05a1f96 100644 --- a/src/components/SearchBar.tsx +++ b/src/components/SearchBar.tsx @@ -48,7 +48,8 @@ export function SearchBar({ onSearch, onFocus, value }: Props) { configs.onChange({ searchMode: newMode, }) - onSearch(value, newMode) + // Skip search if no input to prevent resetting folder expansions + if (value) onSearch(value, newMode) }} aria-label={toggleButtonDescription} > diff --git a/src/utils/VisibleNodesGenerator.ts b/src/utils/VisibleNodesGenerator.ts index b4858c8..f1f9fe2 100644 --- a/src/utils/VisibleNodesGenerator.ts +++ b/src/utils/VisibleNodesGenerator.ts @@ -322,6 +322,7 @@ class FlattenLayer extends CompressLayer { this.expandedNodes.clear() if (restoreExpandedFolders) { this.backupExpandedNodes.forEach(path => this.expandedNodes.add(path)) + this.backupExpandedNodes.clear() } } }