Skip to content

Commit b40bbdd

Browse files
authored
* Cleanup expansion context key * Fix microsoft#155131
1 parent 5315bc8 commit b40bbdd

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/vs/workbench/contrib/files/browser/views/explorerView.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,28 @@ interface IExplorerViewStyles {
6767
listDropBackground?: Color;
6868
}
6969

70-
// Accepts a single or multiple workspace folders
71-
function hasExpandedRootChild(tree: WorkbenchCompressibleAsyncDataTree<ExplorerItem | ExplorerItem[], ExplorerItem, FuzzyScore>, treeInput: ExplorerItem | ExplorerItem[]): boolean {
72-
const inputsToCheck = [];
73-
if (Array.isArray(treeInput)) {
74-
inputsToCheck.push(...treeInput.filter(folder => tree.hasNode(folder) && !tree.isCollapsed(folder)));
75-
} else {
76-
inputsToCheck.push(treeInput);
77-
}
78-
79-
for (const folder of inputsToCheck) {
80-
for (const [, child] of folder.children.entries()) {
81-
if (tree.hasNode(child) && tree.isCollapsible(child) && !tree.isCollapsed(child)) {
82-
return true;
70+
function hasExpandedRootChild(tree: WorkbenchCompressibleAsyncDataTree<ExplorerItem | ExplorerItem[], ExplorerItem, FuzzyScore>, treeInput: ExplorerItem[]): boolean {
71+
for (const folder of treeInput) {
72+
if (tree.hasNode(folder) && !tree.isCollapsed(folder)) {
73+
for (const [, child] of folder.children.entries()) {
74+
if (tree.hasNode(child) && tree.isCollapsible(child) && !tree.isCollapsed(child)) {
75+
return true;
76+
}
8377
}
8478
}
8579
}
80+
return false;
81+
}
8682

83+
/**
84+
* Whether or not any of the nodes in the tree are expanded
85+
*/
86+
function hasExpandedNode(tree: WorkbenchCompressibleAsyncDataTree<ExplorerItem | ExplorerItem[], ExplorerItem, FuzzyScore>, treeInput: ExplorerItem[]): boolean {
87+
for (const folder of treeInput) {
88+
if (tree.hasNode(folder) && !tree.isCollapsed(folder)) {
89+
return true;
90+
}
91+
}
8792
return false;
8893
}
8994

@@ -786,15 +791,6 @@ export class ExplorerView extends ViewPane implements IExplorerView {
786791
this.tree.domFocus();
787792
}
788793

789-
const treeInput = this.tree.getInput();
790-
if (Array.isArray(treeInput)) {
791-
treeInput.forEach(folder => {
792-
folder.children.forEach(child => this.tree.hasNode(child) && this.tree.expand(child, true));
793-
});
794-
795-
return;
796-
}
797-
798794
this.tree.expandAll();
799795
}
800796

@@ -871,7 +867,9 @@ export class ExplorerView extends ViewPane implements IExplorerView {
871867
if (treeInput === undefined) {
872868
return;
873869
}
874-
this.viewHasSomeCollapsibleRootItem.set(hasExpandedRootChild(this.tree, treeInput));
870+
const treeInputArray = Array.isArray(treeInput) ? treeInput : Array.from(treeInput.children.values());
871+
// Has collapsible root when anything is expanded
872+
this.viewHasSomeCollapsibleRootItem.set(hasExpandedNode(this.tree, treeInputArray));
875873
}
876874

877875
styleListDropBackground(styles: IExplorerViewStyles): void {

0 commit comments

Comments
 (0)