fix(sidebar): preserve results when enabling regex search

This commit is contained in:
OOMEcho authored and GitHub committed 2026-09-29 11:56:31 +08:00
1 parent 77c542248d
commit 03b3f4c4fa
3 files changed
+22 -3

No files matched your search

@@ -25,7 +25,7 @@ import {
localTableSearchParentTypes,
} from "@/lib/sidebar/sidebarSearchTree";
import { createSidebarLabelMatcher } from "@/lib/sidebar/sidebarSearch";
import { collectSidebarRegexIndexScopes, resolveSidebarRemoteSearchQuery, resolveSidebarSearchDispatchMode } from "@/lib/sidebar/sidebarRegexSearchIndex";
import { collectSidebarRegexIndexScopes, resolveSidebarRemoteSearchQuery, resolveSidebarSearchDispatchMode, shouldRestoreTrackedSidebarSearchTargetsInRegexMode } from "@/lib/sidebar/sidebarRegexSearchIndex";
import { needsSidebarObjectGroupDiscovery } from "@/lib/sidebar/sidebarSearchDiscovery";
import { createSidebarSearchExpansionState } from "@/lib/sidebar/sidebarSearchExpansionState";
import { createSidebarSearchLoadingTracker } from "@/lib/sidebar/sidebarSearchLoadingTracker";
@@ -301,7 +301,10 @@ watch([deferredSearchQuery, regexMode], ([newQuery, isRegexMode], [oldQuery, was
if (dispatchMode === "regex") {
// Regex search is a read-only projection over live nodes and the local
// table index. It must never trigger ensureConnected/listTables.
const restoreTasks = restoreTrackedSearchTargets();
// Keep results already loaded by an ordinary query until the regex is
// cleared. Restoring them here can empty the tree when this connection has
// no complete local table index yet (for example: "user" -> Regex mode).
const restoreTasks = shouldRestoreTrackedSidebarSearchTargetsInRegexMode(newQuery) ? restoreTrackedSearchTargets() : [];
const searchGeneration = sidebarSearchLoadingTracker.begin();
isSidebarSearchLoading.value = true;
void Promise.allSettled([loadRegexTableSearchIndexes(), runSidebarSearchTasks(restoreTasks)])
@@ -106,3 +106,13 @@ export function resolveSidebarSearchDispatchMode(transition: SidebarSearchTransi
if (transition.wasRegexMode && !transition.query) return "none";
return "ordinary";
}
/**
* Keep an ordinary-search projection available while a non-empty regex is
* filtering it. Restoring those tracked nodes on the mode switch can remove
* the only currently loaded matches before a local table index exists. The
* projection is restored once the regex query is cleared.
*/
export function shouldRestoreTrackedSidebarSearchTargetsInRegexMode(query: string): boolean {
return query.length === 0;
}