Skip to content

Commit f1cd45c

Browse files
committed
1 parent 7ccfdd3 commit f1cd45c

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,16 +307,8 @@ export class ExplorerView extends ViewletPanel {
307307
ExplorerFocusedContext.bindTo(this.tree.contextKeyService);
308308

309309
// Update resource context based on focused element
310-
this.disposables.push(this.tree.onDidChangeFocus(e => {
311-
const stat = e.elements && e.elements.length ? e.elements[0] : undefined;
312-
const isSingleFolder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER;
313-
const resource = stat ? stat.resource : isSingleFolder ? this.contextService.getWorkspace().folders[0].uri : undefined;
314-
this.resourceContext.set(resource);
315-
this.folderContext.set((isSingleFolder && !stat) || !!stat && stat.isDirectory);
316-
this.readonlyContext.set(!!stat && stat.isReadonly);
317-
this.rootContext.set(!stat || (stat && stat.isRoot));
318-
}));
319-
310+
this.disposables.push(this.tree.onDidChangeFocus(e => this.onFocusChanged(e.elements)));
311+
this.onFocusChanged([]);
320312
const explorerNavigator = new TreeResourceNavigator2(this.tree);
321313
this.disposables.push(explorerNavigator);
322314
// Open when selecting via keyboard
@@ -413,6 +405,16 @@ export class ExplorerView extends ViewletPanel {
413405
});
414406
}
415407

408+
private onFocusChanged(elements: ExplorerItem[]): void {
409+
const stat = elements && elements.length ? elements[0] : undefined;
410+
const isSingleFolder = this.contextService.getWorkbenchState() === WorkbenchState.FOLDER;
411+
const resource = stat ? stat.resource : isSingleFolder ? this.contextService.getWorkspace().folders[0].uri : undefined;
412+
this.resourceContext.set(resource);
413+
this.folderContext.set((isSingleFolder && !stat) || !!stat && stat.isDirectory);
414+
this.readonlyContext.set(!!stat && stat.isReadonly);
415+
this.rootContext.set(!stat || (stat && stat.isRoot));
416+
}
417+
416418
// General methods
417419

418420
/**

0 commit comments

Comments
 (0)