API tweaks for grid editor (#51876)

* fix #51001

* add onDidChangeTextEditorViewColumn test that validates moving editor group

* adopt vscode.ViewColumn.Beside

* add vscode.setEditorLayout command
This commit is contained in:
Benjamin Pasero
2018-06-14 17:17:39 +02:00
committed by GitHub
parent 7263a26f9c
commit 2ec2cf597a
10 changed files with 185 additions and 65 deletions

View File

@@ -10,6 +10,7 @@ import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import { CommandsRegistry, ICommandService, ICommandHandler } from 'vs/platform/commands/common/commands';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { EditorGroupLayout } from 'vs/workbench/services/group/common/editorGroupsService';
// -----------------------------------------------------------------
// The following commands are registered on both sides separately.
@@ -98,3 +99,11 @@ export class RemoveFromRecentlyOpenedAPICommand {
}
}
CommandsRegistry.registerCommand(RemoveFromRecentlyOpenedAPICommand.ID, adjustHandler(RemoveFromRecentlyOpenedAPICommand.execute));
export class SetEditorLayoutAPICommand {
public static ID = 'vscode.setEditorLayout';
public static execute(executor: ICommandsExecutor, layout: EditorGroupLayout): Thenable<any> {
return executor.executeCommand('layoutEditorGroups', layout);
}
}
CommandsRegistry.registerCommand(SetEditorLayoutAPICommand.ID, adjustHandler(SetEditorLayoutAPICommand.execute));

View File

@@ -17,7 +17,8 @@ import * as search from 'vs/workbench/parts/search/common/search';
import { ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
import { CustomCodeAction } from 'vs/workbench/api/node/extHostLanguageFeatures';
import { ICommandsExecutor, PreviewHTMLAPICommand, OpenFolderAPICommand, DiffAPICommand, OpenAPICommand, RemoveFromRecentlyOpenedAPICommand } from './apiCommands';
import { ICommandsExecutor, PreviewHTMLAPICommand, OpenFolderAPICommand, DiffAPICommand, OpenAPICommand, RemoveFromRecentlyOpenedAPICommand, SetEditorLayoutAPICommand } from './apiCommands';
import { EditorGroupLayout } from 'vs/workbench/services/group/common/editorGroupsService';
export class ExtHostApiCommands {
@@ -249,6 +250,13 @@ export class ExtHostApiCommands {
{ name: 'path', description: 'Path to remove from recently opened.', constraint: (value: any) => typeof value === 'string' }
]
});
this._register(SetEditorLayoutAPICommand.ID, adjustHandler(SetEditorLayoutAPICommand.execute), {
description: 'Sets the editor layout. The layout is described as object with an initial (optional) orientation (0 = horizontal, 1 = vertical) and an array of editor groups within. Each editor group can have a size and another array of editor groups that will be layed out orthogonal to the orientation. If editor group sizes are provided, their sum must be 1 to be applied per row or column. Example for a 2x2 grid: `{ orientation: 0, groups: [{ groups: [{}, {}], size: 0.5 }, { groups: [{}, {}], size: 0.5 }] }`',
args: [
{ name: 'layout', description: 'The editor layout to set.', constraint: (value: EditorGroupLayout) => typeof value === 'object' && Array.isArray(value.groups) }
]
});
}
// --- command impl

View File

@@ -23,6 +23,7 @@ import { IRelativePattern } from 'vs/base/common/glob';
import * as languageSelector from 'vs/editor/common/modes/languageSelector';
import { WorkspaceEditDto, ResourceTextEditDto } from 'vs/workbench/api/node/extHost.protocol';
import { MarkerSeverity, IRelatedInformation, IMarkerData, MarkerTag } from 'vs/platform/markers/common/markers';
import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
export interface PositionLike {
line: number;
@@ -159,29 +160,22 @@ export namespace DiagnosticSeverity {
export namespace ViewColumn {
export function from(column?: vscode.ViewColumn): EditorViewColumn {
let editorColumn: EditorViewColumn;
if (column === <number>types.ViewColumn.One) {
editorColumn = 0;
} else if (column === <number>types.ViewColumn.Two) {
editorColumn = 1;
} else if (column === <number>types.ViewColumn.Three) {
editorColumn = 2;
} else {
// in any other case (no column or ViewColumn.Active), leave the
// editorColumn as undefined which signals to use the active column
editorColumn = undefined;
if (typeof column === 'number' && column >= types.ViewColumn.One) {
return column - 1; // adjust zero index (ViewColumn.ONE => 0)
}
return editorColumn;
if (column === types.ViewColumn.Beside) {
return SIDE_GROUP;
}
return ACTIVE_GROUP; // default is always the active group
}
export function to(position?: EditorViewColumn): vscode.ViewColumn {
if (position === 0) {
return <number>types.ViewColumn.One;
} else if (position === 1) {
return <number>types.ViewColumn.Two;
} else if (position === 2) {
return <number>types.ViewColumn.Three;
if (typeof position === 'number' && position >= 0) {
return position + 1; // adjust to index (ViewColumn.ONE => 1)
}
return undefined;
}
}

View File

@@ -1120,9 +1120,16 @@ export class CompletionList {
export enum ViewColumn {
Active = -1,
Beside = -2,
One = 1,
Two = 2,
Three = 3
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9
}
export enum StatusBarAlignment {