grid - 💄 for viewcolumn conversion

This commit is contained in:
Benjamin Pasero
2018-05-22 08:53:28 +02:00
parent f0abfa346e
commit 2bfb2763fd
11 changed files with 67 additions and 66 deletions

View File

@@ -13,7 +13,7 @@ import { ExtHostContext, ExtHostDocumentsAndEditorsShape, IModelAddedData, IText
import { MainThreadTextEditor } from './mainThreadEditor';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { IEditor } from 'vs/workbench/common/editor';
import { extHostCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { MainThreadDocuments } from 'vs/workbench/api/electron-browser/mainThreadDocuments';
@@ -421,7 +421,7 @@ export class MainThreadDocumentsAndEditors {
};
}
private _findEditorPosition(editor: MainThreadTextEditor): EditorPosition {
private _findEditorPosition(editor: MainThreadTextEditor): EditorViewColumn {
for (let workbenchEditor of this._editorService.visibleControls) {
if (editor.matches(workbenchEditor)) {
return this.findEditorPosition(workbenchEditor);

View File

@@ -18,12 +18,11 @@ import { IRange } from 'vs/editor/common/core/range';
import { ISelection } from 'vs/editor/common/core/selection';
import { IDecorationOptions, IDecorationRenderOptions, ILineChange } from 'vs/editor/common/editorCommon';
import { ISingleEditOperation } from 'vs/editor/common/model';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/shared/editor';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IApplyEditsOptions, ITextEditorConfigurationUpdate, IUndoStopOptions, TextEditorRevealType, WorkspaceEditDto, reviveWorkspaceEditDto } from 'vs/workbench/api/node/extHost.protocol';
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { GroupIdentifier } from 'vs/workbench/common/editor';
import { ExtHostContext, ExtHostEditorsShape, IExtHostContext, ITextDocumentShowOptions, ITextEditorPositionData, MainThreadTextEditorsShape } from '../node/extHost.protocol';
import { MainThreadDocumentsAndEditors } from './mainThreadDocumentsAndEditors';
import { MainThreadTextEditor } from './mainThreadEditor';
@@ -123,7 +122,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
options: editorOptions
};
return this._editorService.openEditor(input, findEditorGroup(this._editorGroupService, options.position)).then(editor => {
return this._editorService.openEditor(input, viewColumnToEditorGroup(this._editorGroupService, options.position)).then(editor => {
if (!editor) {
return undefined;
}
@@ -131,14 +130,14 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
});
}
$tryShowEditor(id: string, position?: EditorPosition): TPromise<void> {
$tryShowEditor(id: string, position?: EditorViewColumn): TPromise<void> {
let mainThreadEditor = this._documentsAndEditors.getEditor(id);
if (mainThreadEditor) {
let model = mainThreadEditor.getModel();
return this._editorService.openEditor({
resource: model.uri,
options: { preserveFocus: false }
}, findEditorGroup(this._editorGroupService, position)).then(() => { return; });
}, viewColumnToEditorGroup(this._editorGroupService, position)).then(() => { return; });
}
return undefined;
}
@@ -247,16 +246,16 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
// --- commands
CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, IEditorOptions, EditorPosition]) {
CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, IEditorOptions, EditorViewColumn]) {
const editorService = accessor.get(IEditorService);
const editorGroupService = accessor.get(IEditorGroupsService);
const [resource, options, position] = args;
return editorService.openEditor({ resource, options }, findEditorGroup(editorGroupService, position)).then(() => void 0);
return editorService.openEditor({ resource, options }, viewColumnToEditorGroup(editorGroupService, position)).then(() => void 0);
});
CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string, IEditorOptions, EditorPosition]) {
CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string, IEditorOptions, EditorViewColumn]) {
const editorService = accessor.get(IEditorService);
const editorGroupService = accessor.get(IEditorGroupsService);
@@ -272,25 +271,5 @@ CommandsRegistry.registerCommand('_workbench.diff', function (accessor: Services
label = localize('diffLeftRightLabel', "{0} ⟷ {1}", leftResource.toString(true), rightResource.toString(true));
}
return editorService.openEditor({ leftResource, rightResource, label, description, options }, findEditorGroup(editorGroupService, position)).then(() => void 0);
});
export function findEditorGroup(editorGroupService: IEditorGroupsService, position?: EditorPosition): GroupIdentifier {
if (typeof position !== 'number') {
return ACTIVE_GROUP; // prefer active group when position is undefined
}
const groups = editorGroupService.groups;
let candidate = groups[position];
if (candidate) {
return candidate.id; // found direct match
}
let firstGroup = groups[0];
if (groups.length === 1 && firstGroup.count === 0) {
return firstGroup.id; // first editor should always open in first group
}
return SIDE_GROUP; // open to the side if group not found
}
return editorService.openEditor({ leftResource, rightResource, label, description, options }, viewColumnToEditorGroup(editorGroupService, position)).then(() => void 0);
});

View File

@@ -8,7 +8,7 @@ import URI, { UriComponents } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { localize } from 'vs/nls';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/shared/editor';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle } from 'vs/workbench/api/node/extHost.protocol';
@@ -19,7 +19,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { extHostNamedCustomer } from './extHostCustomers';
import { findEditorGroup } from 'vs/workbench/api/electron-browser/mainThreadEditors';
import { GroupIdentifier } from 'vs/workbench/common/editor';
@extHostNamedCustomer(MainContext.MainThreadWebviews)
@@ -69,14 +68,14 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
handle: WebviewPanelHandle,
viewType: string,
title: string,
showOptions: { viewColumn: EditorPosition | null, preserveFocus: boolean },
showOptions: { viewColumn: EditorViewColumn | null, preserveFocus: boolean },
options: WebviewInputOptions,
extensionLocation: UriComponents
): void {
const mainThreadShowOptions: ICreateWebViewShowOptions = Object.create(null);
if (showOptions) {
mainThreadShowOptions.preserveFocus = showOptions.preserveFocus;
mainThreadShowOptions.group = findEditorGroup(this._editorGroupService, showOptions.viewColumn);
mainThreadShowOptions.group = viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn);
}
const webview = this._webviewService.createWebview(MainThreadWebviews.viewType, title, mainThreadShowOptions, options, URI.revive(extensionLocation), this.createWebviewEventDelegate(handle));
@@ -104,13 +103,13 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
webview.html = value;
}
$reveal(handle: WebviewPanelHandle, viewColumn: EditorPosition | null, preserveFocus: boolean): void {
$reveal(handle: WebviewPanelHandle, viewColumn: EditorViewColumn | null, preserveFocus: boolean): void {
const webview = this.getWebview(handle);
if (webview.isDisposed()) {
return;
}
const targetGroup = this._editorGroupService.getGroup(findEditorGroup(this._editorGroupService, viewColumn));
const targetGroup = this._editorGroupService.getGroup(viewColumnToEditorGroup(this._editorGroupService, viewColumn));
this._webviewService.revealWebview(webview, targetGroup || this._editorGroupService.activeGroup, preserveFocus);
}

View File

@@ -9,7 +9,7 @@ import * as vscode from 'vscode';
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 { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
// -----------------------------------------------------------------
// The following commands are registered on both sides separately.
@@ -71,7 +71,7 @@ export class OpenAPICommand {
public static ID = 'vscode.open';
public static execute(executor: ICommandsExecutor, resource: URI, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions): Thenable<any> {
let options: ITextEditorOptions;
let position: EditorPosition;
let position: EditorViewColumn;
if (columnOrOptions) {
if (typeof columnOrOptions === 'number') {

View File

@@ -13,7 +13,7 @@ import Severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
import { IMarkerData } from 'vs/platform/markers/common/markers';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry';
@@ -181,7 +181,7 @@ export interface IApplyEditsOptions extends IUndoStopOptions {
}
export interface ITextDocumentShowOptions {
position?: EditorPosition;
position?: EditorViewColumn;
preserveFocus?: boolean;
pinned?: boolean;
selection?: IRange;
@@ -191,7 +191,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
$tryShowTextDocument(resource: UriComponents, options: ITextDocumentShowOptions): TPromise<string>;
$registerTextEditorDecorationType(key: string, options: editorCommon.IDecorationRenderOptions): void;
$removeTextEditorDecorationType(key: string): void;
$tryShowEditor(id: string, position: EditorPosition): TPromise<void>;
$tryShowEditor(id: string, position: EditorViewColumn): TPromise<void>;
$tryHideEditor(id: string): TPromise<void>;
$trySetOptions(id: string, options: ITextEditorConfigurationUpdate): TPromise<void>;
$trySetDecorations(id: string, key: string, ranges: editorCommon.IDecorationOptions[]): TPromise<void>;
@@ -356,9 +356,9 @@ export interface MainThreadTelemetryShape extends IDisposable {
export type WebviewPanelHandle = string;
export interface MainThreadWebviewsShape extends IDisposable {
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, viewOptions: { viewColumn: EditorPosition, preserveFocus: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionLocation: UriComponents): void;
$createWebviewPanel(handle: WebviewPanelHandle, viewType: string, title: string, viewOptions: { viewColumn: EditorViewColumn, preserveFocus: boolean }, options: vscode.WebviewPanelOptions & vscode.WebviewOptions, extensionLocation: UriComponents): void;
$disposeWebview(handle: WebviewPanelHandle): void;
$reveal(handle: WebviewPanelHandle, viewColumn: EditorPosition | null, preserveFocus: boolean): void;
$reveal(handle: WebviewPanelHandle, viewColumn: EditorViewColumn | null, preserveFocus: boolean): void;
$setTitle(handle: WebviewPanelHandle, value: string): void;
$setHtml(handle: WebviewPanelHandle, value: string): void;
$postMessage(handle: WebviewPanelHandle, value: any): Thenable<boolean>;
@@ -369,9 +369,9 @@ export interface MainThreadWebviewsShape extends IDisposable {
export interface ExtHostWebviewsShape {
$onMessage(handle: WebviewPanelHandle, message: any): void;
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, active: boolean, position: EditorPosition): void;
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, active: boolean, position: EditorViewColumn): void;
$onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Thenable<void>;
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<void>;
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: vscode.WebviewOptions): Thenable<void>;
}
export interface MainThreadUrlsShape extends IDisposable {
@@ -543,10 +543,10 @@ export interface ITextEditorAddData {
options: IResolvedTextEditorConfiguration;
selections: ISelection[];
visibleRanges: IRange[];
editorPosition: EditorPosition;
editorPosition: EditorViewColumn;
}
export interface ITextEditorPositionData {
[id: string]: EditorPosition;
[id: string]: EditorViewColumn;
}
export interface IEditorPropertiesChangeData {
options: IResolvedTextEditorConfiguration | null;

View File

@@ -11,7 +11,7 @@ import { TextEditorSelectionChangeKind } from './extHostTypes';
import * as TypeConverters from './extHostTypeConverters';
import { TextEditorDecorationType, ExtHostTextEditor } from './extHostTextEditor';
import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { MainContext, MainThreadTextEditorsShape, ExtHostEditorsShape, ITextDocumentShowOptions, ITextEditorPositionData, IMainContext, WorkspaceEditDto, IEditorPropertiesChangeData } from './extHost.protocol';
import * as vscode from 'vscode';
@@ -73,7 +73,7 @@ export class ExtHostEditors implements ExtHostEditorsShape {
};
} else {
options = {
position: 0 as EditorPosition,
position: 0 as EditorViewColumn,
preserveFocus: false
};
}

View File

@@ -7,7 +7,7 @@
import * as modes from 'vs/editor/common/modes';
import * as types from './extHostTypes';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
import { EndOfLineSequence } from 'vs/editor/common/model';
import * as vscode from 'vscode';
@@ -157,7 +157,7 @@ export namespace DiagnosticSeverity {
}
export namespace ViewColumn {
export function from(column?: vscode.ViewColumn): EditorPosition {
export function from(column?: vscode.ViewColumn): EditorViewColumn {
let editorColumn = 0;
if (typeof column !== 'number') {
// stick with ONE
@@ -171,7 +171,7 @@ export namespace ViewColumn {
return editorColumn;
}
export function to(position?: EditorPosition): vscode.ViewColumn {
export function to(position?: EditorViewColumn): vscode.ViewColumn {
if (typeof position !== 'number') {
return undefined;
}

View File

@@ -7,7 +7,7 @@ import { MainContext, MainThreadWebviewsShape, IMainContext, ExtHostWebviewsShap
import * as vscode from 'vscode';
import { Event, Emitter } from 'vs/base/common/event';
import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters';
import { EditorPosition } from 'vs/workbench/api/shared/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { TPromise } from 'vs/base/common/winjs.base';
import { Disposable } from './extHostTypes';
import URI from 'vs/base/common/uri';
@@ -248,7 +248,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
}
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, visible: boolean, position: EditorPosition): void {
$onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, visible: boolean, position: EditorViewColumn): void {
const panel = this.getWebviewPanel(handle);
if (panel) {
const viewColumn = typeConverters.ViewColumn.to(position);
@@ -274,7 +274,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
viewType: string,
title: string,
state: any,
position: EditorPosition,
position: EditorViewColumn,
options: vscode.WebviewOptions & vscode.WebviewPanelOptions
): Thenable<void> {
const serializer = this._serializers.get(viewType);

View File

@@ -5,7 +5,31 @@
'use strict';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
import { GroupIdentifier } from 'vs/workbench/common/editor';
import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
// TODO@api this was previously a hardcoded list of editor positions (ONE, TWO, THREE)
// that with the introduction of grid editor feature is now unbounded. This should be
// revisited when the grid functionality is exposed to extensions
export type EditorPosition = number;
export type EditorViewColumn = number;
export function viewColumnToEditorGroup(editorGroupService: IEditorGroupsService, position?: EditorViewColumn): GroupIdentifier {
if (typeof position !== 'number') {
return ACTIVE_GROUP; // prefer active group when position is undefined
}
const groups = editorGroupService.groups;
let candidate = groups[position];
if (candidate) {
return candidate.id; // found direct match
}
let firstGroup = groups[0];
if (groups.length === 1 && firstGroup.count === 0) {
return firstGroup.id; // first editor should always open in first group
}
return SIDE_GROUP; // open to the side if group not found
}