diff --git a/src/vs/workbench/contrib/files/browser/views/explorerView.ts b/src/vs/workbench/contrib/files/browser/views/explorerView.ts index 334a3cd7f900a418b747fffa9445c29e900a0f7f..3818224642c77bb64bb1e39a054c27eac3519a05 100644 --- a/src/vs/workbench/contrib/files/browser/views/explorerView.ts +++ b/src/vs/workbench/contrib/files/browser/views/explorerView.ts @@ -6,7 +6,6 @@ import * as nls from 'vs/nls'; import { URI } from 'vs/base/common/uri'; import * as perf from 'vs/base/common/performance'; -import { sequence } from 'vs/base/common/async'; import { Action, IAction } from 'vs/base/common/actions'; import { memoize } from 'vs/base/common/decorators'; import { IFilesConfiguration, ExplorerFolderContext, FilesExplorerFocusedContext, ExplorerFocusedContext, ExplorerRootContext, ExplorerResourceReadonlyContext, IExplorerService, ExplorerResourceCut } from 'vs/workbench/contrib/files/common/files'; @@ -49,6 +48,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService import { isMacintosh } from 'vs/base/common/platform'; import { KeyCode } from 'vs/base/common/keyCodes'; import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; +import { isEqualOrParent } from 'vs/base/common/resources'; export class ExplorerView extends ViewletPanel { static readonly ID: string = 'workbench.explorer.fileView'; @@ -188,7 +188,7 @@ export class ExplorerView extends ViewletPanel { this.tree.domFocus(); } })); - this.disposables.push(this.explorerService.onDidSelectItem(e => this.onSelectItem(e.item, e.reveal))); + this.disposables.push(this.explorerService.onDidSelectResource(e => this.onSelectResource(e.resource, e.reveal))); this.disposables.push(this.explorerService.onDidCopyItems(e => this.onCopyItems(e.items, e.cut, e.previouslyCutItems))); // Update configuration @@ -507,27 +507,35 @@ export class ExplorerView extends ViewletPanel { return toResource(input, { supportSideBySide: true }); } - private onSelectItem(fileStat: ExplorerItem, reveal = this.autoReveal): Promise { - if (!fileStat || !this.isBodyVisible() || this.tree.getInput() === fileStat) { - return Promise.resolve(undefined); + private onSelectResource(resource: URI, reveal = this.autoReveal): void { + if (!resource || !this.isBodyVisible()) { + return; } // Expand all stats in the parent chain - const toExpand: ExplorerItem[] = []; - let parent = fileStat.parent; - while (parent) { - toExpand.push(parent); - parent = parent.parent; - } - - return sequence(toExpand.reverse().map(s => () => this.tree.expand(s))).then(() => { - if (reveal) { - this.tree.reveal(fileStat, 0.5); - } + const root = this.explorerService.roots.filter(r => isEqualOrParent(resource, r.resource)).pop(); + if (root) { + const traverse = async (item: ExplorerItem) => { + if (item.resource.toString() === resource.toString()) { + if (reveal) { + this.tree.reveal(item, 0.5); + } - this.tree.setFocus([fileStat]); - this.tree.setSelection([fileStat]); - }); + this.tree.setFocus([item]); + this.tree.setSelection([item]); + } else { + await this.tree.expand(item); + let found = false; + item.children.forEach(async child => { + if (!found && isEqualOrParent(resource, child.resource)) { + found = true; + await traverse(child); + } + }); + } + }; + traverse(root); + } } private onCopyItems(stats: ExplorerItem[], cut: boolean, previousCut: ExplorerItem[]): void { diff --git a/src/vs/workbench/contrib/files/common/explorerService.ts b/src/vs/workbench/contrib/files/common/explorerService.ts index 7ce193360b2e3c08ede284ea14759b3e4741d83b..4e0a0394c8e1c934050f44c5a4a33c67e2805f0f 100644 --- a/src/vs/workbench/contrib/files/common/explorerService.ts +++ b/src/vs/workbench/contrib/files/common/explorerService.ts @@ -34,7 +34,7 @@ export class ExplorerService implements IExplorerService { private _onDidChangeRoots = new Emitter(); private _onDidChangeItem = new Emitter(); private _onDidChangeEditable = new Emitter(); - private _onDidSelectItem = new Emitter<{ item?: ExplorerItem, reveal?: boolean }>(); + private _onDidSelectResource = new Emitter<{ resource?: URI, reveal?: boolean }>(); private _onDidCopyItems = new Emitter<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>(); private disposables: IDisposable[] = []; private editable: { stat: ExplorerItem, data: IEditableData } | undefined; @@ -68,8 +68,8 @@ export class ExplorerService implements IExplorerService { return this._onDidChangeEditable.event; } - get onDidSelectItem(): Event<{ item?: ExplorerItem, reveal?: boolean }> { - return this._onDidSelectItem.event; + get onDidSelectResource(): Event<{ resource?: URI, reveal?: boolean }> { + return this._onDidSelectResource.event; } get onDidCopyItems(): Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }> { @@ -142,7 +142,7 @@ export class ExplorerService implements IExplorerService { select(resource: URI, reveal?: boolean): Promise { const fileStat = this.findClosest(resource); if (fileStat) { - this._onDidSelectItem.fire({ item: fileStat, reveal }); + this._onDidSelectResource.fire({ resource: fileStat.resource, reveal }); return Promise.resolve(undefined); } @@ -161,7 +161,7 @@ export class ExplorerService implements IExplorerService { this._onDidChangeItem.fire(item ? item.parent : undefined); // Select and Reveal - this._onDidSelectItem.fire({ item: item || undefined, reveal }); + this._onDidSelectResource.fire({ resource: item ? item.resource : undefined, reveal }); }, () => { root.isError = true; this._onDidChangeItem.fire(root); diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts index fd9d942093e490bcbf925ebe15731d62b91296b9..e666d56871ebdbfeed2f675ac1b1442bb220716c 100644 --- a/src/vs/workbench/contrib/files/common/files.ts +++ b/src/vs/workbench/contrib/files/common/files.ts @@ -44,7 +44,7 @@ export interface IExplorerService { readonly onDidChangeRoots: Event; readonly onDidChangeItem: Event; readonly onDidChangeEditable: Event; - readonly onDidSelectItem: Event<{ item?: ExplorerItem, reveal?: boolean }>; + readonly onDidSelectResource: Event<{ resource?: URI, reveal?: boolean }>; readonly onDidCopyItems: Event<{ items: ExplorerItem[], cut: boolean, previouslyCutItems: ExplorerItem[] | undefined }>; setEditable(stat: ExplorerItem, data: IEditableData | null): void;