Skip to content

Commit ccb631c

Browse files
committed
explorer: expand root folder properly
fixes microsoft#31195
1 parent 2169790 commit ccb631c

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { FileStat, Model } from 'vs/workbench/parts/files/common/explorerModel';
3232
import { IListService } from 'vs/platform/list/browser/listService';
3333
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
3434
import { IPartService } from 'vs/workbench/services/part/common/partService';
35-
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
35+
import { IWorkspaceContextService, WorkbenchState, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
3636
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
3737
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3838
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -166,7 +166,7 @@ export class ExplorerView extends CollapsibleView {
166166
};
167167

168168
this.toDispose.push(this.themeService.onDidFileIconThemeChange(onFileIconThemeChange));
169-
this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders(() => this.refreshFromEvent()));
169+
this.toDispose.push(this.contextService.onDidChangeWorkspaceFolders((e) => this.refreshFromEvent(e.added)));
170170
onFileIconThemeChange(this.themeService.getFileIconTheme());
171171
}
172172

@@ -676,11 +676,11 @@ export class ExplorerView extends CollapsibleView {
676676
}));
677677
}
678678

679-
private refreshFromEvent(): void {
679+
private refreshFromEvent(newRoots: WorkspaceFolder[] = []): void {
680680
if (this.isVisible()) {
681681
this.explorerRefreshDelayer.trigger(() => {
682682
if (!this.explorerViewer.getHighlight()) {
683-
return this.doRefresh();
683+
return this.doRefresh(newRoots);
684684
}
685685

686686
return TPromise.as(null);
@@ -722,7 +722,7 @@ export class ExplorerView extends CollapsibleView {
722722
});
723723
}
724724

725-
private doRefresh(): TPromise<void> {
725+
private doRefresh(newRoots: WorkspaceFolder[] = []): TPromise<void> {
726726
const targetsToResolve: { root: FileStat, resource: URI, options: { resolveTo: URI[] } }[] = [];
727727
this.model.roots.forEach(root => {
728728
const rootAndTargets = { root, resource: root.resource, options: { resolveTo: [] } };
@@ -732,9 +732,8 @@ export class ExplorerView extends CollapsibleView {
732732
let targetsToExpand: URI[] = [];
733733
if (this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES]) {
734734
targetsToExpand = this.settings[ExplorerView.MEMENTO_EXPANDED_FOLDER_RESOURCES].map((e: string) => URI.parse(e));
735-
} else if (this.model.roots.length === 1) {
736-
targetsToExpand = this.model.roots.map(root => root.resource); // always expand if there is just one root
737735
}
736+
targetsToExpand.push(...newRoots.map(r => r.uri));
738737

739738
// First time refresh: Receive target through active editor input or selection and also include settings from previous session
740739
if (!this.isCreated) {
@@ -784,16 +783,11 @@ export class ExplorerView extends CollapsibleView {
784783
modelStats.forEach((modelStat, index) => FileStat.mergeLocalWithDisk(modelStat, this.model.roots[index]));
785784

786785
const input = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER ? this.model.roots[0] : this.model;
786+
const statsToExpand = this.explorerViewer.getExpandedElements().concat(targetsToExpand.map(target => this.model.findClosest(target)));
787787
if (input === this.explorerViewer.getInput()) {
788-
return this.explorerViewer.refresh();
788+
return this.explorerViewer.refresh().then(() => this.explorerViewer.expandAll(statsToExpand));
789789
}
790790

791-
// Preserve expanded elements if tree input changed.
792-
// If it is a brand new tree just expand elements from memento
793-
const expanded = this.explorerViewer.getExpandedElements();
794-
const statsToExpand = expanded.length ? [this.model.roots[0]].concat(expanded) :
795-
targetsToExpand.map(expand => this.model.findClosest(expand));
796-
797791
// Display roots only when multi folder workspace
798792
// Make sure to expand all folders that where expanded in the previous session
799793
return this.explorerViewer.setInput(input).then(() => this.explorerViewer.expandAll(statsToExpand));

0 commit comments

Comments
 (0)