From fec2b499d5cfee8622bd849cc3cf573ca1e5ada6 Mon Sep 17 00:00:00 2001 From: Andrea Mah <31675041+andreamah@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:30:09 -0700 Subject: [PATCH] fixed bug with collapsing compressed nodes (#162222) fixed bug with collapsing compression nodes --- .../contrib/search/browser/searchActions.ts | 20 ++++++++++++++++--- .../search/browser/searchResultsView.ts | 2 ++ .../contrib/search/common/searchModel.ts | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/vs/workbench/contrib/search/browser/searchActions.ts b/src/vs/workbench/contrib/search/browser/searchActions.ts index cddc3dd9e41..6f121ec4d6f 100644 --- a/src/vs/workbench/contrib/search/browser/searchActions.ts +++ b/src/vs/workbench/contrib/search/browser/searchActions.ts @@ -292,14 +292,21 @@ export function collapseDeepestExpandedLevel(accessor: ServicesAccessor) { let canCollapseFileMatchLevel = false; let canCollapseFirstLevel = false; - if (node instanceof FolderMatch) { + if (node instanceof FolderMatchWorkspaceRoot) { while (node = navigator.next()) { if (node instanceof Match) { canCollapseFileMatchLevel = true; break; } if (searchView.isTreeLayoutViewVisible && !canCollapseFirstLevel) { - const immediateParent = node.parent(); + let nodeToTest = node; + + if (node instanceof FolderMatch) { + nodeToTest = node.compressionStartParent ?? node; + } + + const immediateParent = nodeToTest.parent(); + if (!(immediateParent instanceof FolderMatchWorkspaceRoot || immediateParent instanceof FolderMatchNoRoot || immediateParent instanceof SearchResult)) { canCollapseFirstLevel = true; } @@ -318,7 +325,14 @@ export function collapseDeepestExpandedLevel(accessor: ServicesAccessor) { node = navigator.first(); if (node) { do { - const immediateParent = node.parent(); + + let nodeToTest = node; + + if (node instanceof FolderMatch) { + nodeToTest = node.compressionStartParent ?? node; + } + const immediateParent = nodeToTest.parent(); + if (immediateParent instanceof FolderMatchWorkspaceRoot || immediateParent instanceof FolderMatchNoRoot) { if (viewer.hasElement(node)) { viewer.collapse(node, true); diff --git a/src/vs/workbench/contrib/search/browser/searchResultsView.ts b/src/vs/workbench/contrib/search/browser/searchResultsView.ts index 61e04bbf36a..5ddcc2e1134 100644 --- a/src/vs/workbench/contrib/search/browser/searchResultsView.ts +++ b/src/vs/workbench/contrib/search/browser/searchResultsView.ts @@ -95,6 +95,7 @@ export class FolderMatchRenderer extends Disposable implements ICompressibleTree renderCompressedElements(node: ITreeNode, any>, index: number, templateData: IFolderMatchTemplate, height: number | undefined): void { const compressed = node.element; const folder = compressed.elements[compressed.elements.length - 1]; + folder.compressionStartParent = compressed.elements[0]; const label = compressed.elements.map(e => e.name()); if (folder.resource) { @@ -134,6 +135,7 @@ export class FolderMatchRenderer extends Disposable implements ICompressibleTree renderElement(node: ITreeNode, index: number, templateData: IFolderMatchTemplate): void { const folderMatch = node.element; + folderMatch.compressionStartParent = undefined; if (folderMatch.resource) { const workspaceFolder = this.contextService.getWorkspaceFolder(folderMatch.resource); if (workspaceFolder && isEqual(workspaceFolder.uri, folderMatch.resource)) { diff --git a/src/vs/workbench/contrib/search/common/searchModel.ts b/src/vs/workbench/contrib/search/common/searchModel.ts index 0aafd7dbff6..daadea9af49 100644 --- a/src/vs/workbench/contrib/search/common/searchModel.ts +++ b/src/vs/workbench/contrib/search/common/searchModel.ts @@ -492,6 +492,10 @@ export class FolderMatch extends Disposable { protected _unDisposedFileMatches: ResourceMap; protected _unDisposedFolderMatches: ResourceMap; private _replacingAll: boolean = false; + + // if this is compressed in a node with other FolderMatches, then this is set to the parent where compression starts + public compressionStartParent: FolderMatch | undefined; + constructor( protected _resource: URI | null, private _id: string,