explorer: improve context during multi select

This commit is contained in:
Joao Moreno 2019-11-15 17:10:37 +01:00
parent d030b20a30
commit 6642c09fbf
No known key found for this signature in database
GPG key ID: 9494F5E6167A8E6B
2 changed files with 24 additions and 10 deletions

View file

@ -49,7 +49,7 @@ import { values } from 'vs/base/common/map';
import { first } from 'vs/base/common/arrays';
import { withNullAsUndefined } from 'vs/base/common/types';
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { attachStyler, IColorMapping } from 'vs/platform/theme/common/styler';
import { ColorValue, listDropBackground } from 'vs/platform/theme/common/colorRegistry';
@ -283,23 +283,36 @@ export class ExplorerView extends ViewletPanel {
}
getContext(respectMultiSelection: boolean): ExplorerItem[] {
let stat: ExplorerItem | undefined;
let focusedStat: ExplorerItem | undefined;
if (this.compressedNavigationController) {
stat = this.compressedNavigationController.current;
focusedStat = this.compressedNavigationController.current;
} else {
const focus = this.tree.getFocus();
stat = focus.length ? focus[0] : undefined;
focusedStat = focus.length ? focus[0] : undefined;
}
if (!stat) {
if (!focusedStat) {
return [];
}
const selection = this.tree.getSelection();
if (respectMultiSelection && selection.indexOf(stat) >= 0) {
return selection;
const selectedStats: ExplorerItem[] = [];
for (const stat of this.tree.getSelection()) {
const controller = this.renderer.getCompressedNavigationController(stat);
if (controller) {
selectedStats.push(...controller.items);
} else {
selectedStats.push(stat);
}
}
return [stat];
if (respectMultiSelection && selectedStats.indexOf(focusedStat) >= 0) {
return selectedStats;
}
return [focusedStat];
}
private selectActiveFile(deselect?: boolean, reveal = this.autoReveal): void {

View file

@ -118,6 +118,7 @@ export class ExplorerDataSource implements IAsyncDataSource<ExplorerItem | Explo
export interface ICompressedNavigationController {
readonly current: ExplorerItem;
readonly items: ExplorerItem[];
readonly index: number;
readonly count: number;
previous(): void;
@ -136,7 +137,7 @@ export class CompressedNavigationController implements ICompressedNavigationCont
get count(): number { return this.items.length; }
get current(): ExplorerItem { return this.items[this._index]!; }
constructor(private items: ExplorerItem[], templateData: IFileTemplateData) {
constructor(readonly items: ExplorerItem[], templateData: IFileTemplateData) {
this._index = items.length - 1;
this.labels = Array.from(templateData.container.querySelectorAll('.label-name')) as HTMLElement[];
DOM.addClass(this.labels[this._index], 'active');