Skip to content

Commit

Permalink
editor service: allow to open multiple editors at once side by side
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 10, 2018
1 parent f9f3333 commit 5b83333
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/vs/workbench/browser/parts/editor/editorPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return res;
}

public openEditors(editors: { input: EditorInput, position: Position, options?: EditorOptions }[]): TPromise<IEditor[]> {
public openEditors(editors: { input: EditorInput, position?: Position, options?: EditorOptions }[]): TPromise<IEditor[]>;
public openEditors(editors: { input: EditorInput, options?: EditorOptions }[], sideBySide?: boolean): TPromise<IEditor[]>;
public openEditors(editors: { input: EditorInput, position?: Position, options?: EditorOptions }[], sideBySide?: boolean): TPromise<IEditor[]> {
if (!editors.length) {
return TPromise.as<IEditor[]>([]);
}
Expand All @@ -1112,7 +1114,7 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService

const ratio = this.editorGroupsControl.getRatio();

return this.doOpenEditors(editors, activePosition, ratio);
return this.doOpenEditors(editors, activePosition, ratio, sideBySide);
}

public hasEditorsToRestore(): boolean {
Expand Down Expand Up @@ -1143,7 +1145,15 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
return this._onEditorsChanged.throttle(this.doOpenEditors(editors, activePosition, editorState && editorState.ratio));
}

private doOpenEditors(editors: { input: EditorInput, position: Position, options?: EditorOptions }[], activePosition?: number, ratio?: number[]): TPromise<IEditor[]> {
private doOpenEditors(editors: { input: EditorInput, position?: Position, options?: EditorOptions }[], activePosition?: number, ratio?: number[], sideBySide?: boolean): TPromise<IEditor[]> {

// Find position if not provided already from calling side
editors.forEach(editor => {
if (typeof editor.position !== 'number') {
editor.position = this.findPosition(editor.input, editor.options, sideBySide);
}
});

const positionOneEditors = editors.filter(e => e.position === Position.ONE);
const positionTwoEditors = editors.filter(e => e.position === Position.TWO);
const positionThreeEditors = editors.filter(e => e.position === Position.THREE);
Expand Down
15 changes: 10 additions & 5 deletions src/vs/workbench/services/editor/common/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ export interface IWorkbenchEditorService extends IEditorService {
* Similar to #openEditor() but allows to open multiple editors for different positions at the same time. If there are
* more than one editor per position, only the first one will be active and the others stacked behind inactive.
*/
openEditors(editors: { input: IResourceInputType, position: Position }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IResourceInputType, position?: Position }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, position?: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IResourceInputType }[], sideBySide?: boolean): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[], sideBySide?: boolean): TPromise<IEditor[]>;

/**
* Given a list of editors to replace, will look across all groups where this editor is open (active or hidden)
Expand Down Expand Up @@ -104,7 +106,8 @@ export interface IWorkbenchEditorService extends IEditorService {
export interface IEditorPart {
openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<IEditor>;
openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, position?: Position): TPromise<IEditor>;
openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, position?: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[], sideBySide?: boolean): TPromise<IEditor[]>;
replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[], position?: Position): TPromise<IEditor[]>;
closeEditor(position: Position, input: IEditorInput): TPromise<void>;
closeEditors(position: Position, filter?: { except?: IEditorInput, direction?: Direction, unmodifiedOnly?: boolean }): TPromise<void>;
Expand Down Expand Up @@ -208,7 +211,9 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {

public openEditors(editors: { input: IResourceInputType, position: Position }[]): TPromise<IEditor[]>;
public openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise<IEditor[]>;
public openEditors(editors: any[]): TPromise<IEditor[]> {
public openEditors(editors: { input: IResourceInputType }[], sideBySide?: boolean): TPromise<IEditor[]>;
public openEditors(editors: { input: IEditorInput, options?: IEditorOptions }[], sideBySide?: boolean): TPromise<IEditor[]>;
public openEditors(editors: any[], sideBySide?: boolean): TPromise<IEditor[]> {
const inputs = editors.map(editor => this.createInput(editor.input));
const typedInputs: { input: IEditorInput, position: Position, options?: EditorOptions }[] = inputs.map((input, index) => {
const options = editors[index].input instanceof EditorInput ? this.toOptions(editors[index].options) : TextEditorOptions.from(editors[index].input);
Expand All @@ -220,7 +225,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
};
});

return this.editorPart.openEditors(typedInputs);
return this.editorPart.openEditors(typedInputs, sideBySide);
}

public replaceEditors(editors: { toReplace: IResourceInputType, replaceWith: IResourceInputType }[], position?: Position): TPromise<IEditor[]>;
Expand Down

0 comments on commit 5b83333

Please sign in to comment.