fix(sidebar): preserve table details after filtering

This commit is contained in:
guoyongchang authored and GitHub committed 2026-07-30 14:47:35 +08:00
1 parent e9ea840e1b
commit f82749163d
3 files changed
+85 -4

No files matched your search

@@ -28,6 +28,11 @@ export function filterSidebarTree(nodes: TreeNode[], query: string, collapsedIds
return filterSidebarTreeWithMatcher(nodes, matchLabel, collapsedIds, searchableNodeTypes);
}
export function reuseLiveSidebarTreeNodes(indexedNodes: TreeNode[], liveNodes: readonly TreeNode[]): TreeNode[] {
const liveNodesById = new Map(liveNodes.map((node) => [node.id, node]));
return indexedNodes.map((node) => liveNodesById.get(node.id) ?? node);
}
function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher | undefined, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {
const filteredNodes: { node: TreeNode; score: number }[] = [];
@@ -49,10 +54,13 @@ function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabe
// Type-only filtering keeps matching rows and their ancestor path, but not
// unrelated descendants that would make the selected type appear ignored.
const preservesSubtree = !!matchLabel && !!selfMatch && preserveMatchedSubtreeTypes.has(node.type);
// A type-matched table keeps its loaded detail groups after the text query
// is cleared instead of being rebuilt with an empty filtered child list.
const preservesTypeMatchedTable = !matchLabel && !!selfMatch && node.type === "table";
const filteredChildren = preservesSubtree ? node.children : node.children ? filterSidebarTreeWithMatcher(node.children, matchLabel, collapsedIds, searchableNodeTypes) : undefined;
if (selfMatch || (filteredChildren && filteredChildren.length > 0)) {
if (!node.children) {
if (!node.children || preservesTypeMatchedTable) {
filteredNodes.push({ node, score: selfMatch?.score ?? 0 });
} else {
const children = filteredChildren ?? [];