From 069bbd81e491b8e62d95aa714a9ed2e68d618f36 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 4 May 2018 18:17:34 +0200 Subject: [PATCH] type converters, use namespace for Selection --- .../api/node/extHostDocumentsAndEditors.ts | 2 +- .../workbench/api/node/extHostTextEditor.ts | 2 +- .../workbench/api/node/extHostTextEditors.ts | 4 +-- .../api/node/extHostTypeConverters.ts | 30 ++++++++++--------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts b/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts index e88d80607b5..49e234dc1fd 100644 --- a/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts +++ b/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts @@ -95,7 +95,7 @@ export class ExtHostDocumentsAndEditors implements ExtHostDocumentsAndEditorsSha this._mainContext.getProxy(MainContext.MainThreadTextEditors), data.id, documentData, - data.selections.map(typeConverters.toSelection), + data.selections.map(typeConverters.Selection.to), data.options, data.visibleRanges.map(typeConverters.toRange), typeConverters.toViewColumn(data.editorPosition) diff --git a/src/vs/workbench/api/node/extHostTextEditor.ts b/src/vs/workbench/api/node/extHostTextEditor.ts index f41e633c11c..7b7c4d59716 100644 --- a/src/vs/workbench/api/node/extHostTextEditor.ts +++ b/src/vs/workbench/api/node/extHostTextEditor.ts @@ -474,7 +474,7 @@ export class ExtHostTextEditor implements vscode.TextEditor { } private _trySetSelection(): TPromise { - let selection = this._selections.map(TypeConverters.fromSelection); + let selection = this._selections.map(TypeConverters.Selection.from); return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection)); } diff --git a/src/vs/workbench/api/node/extHostTextEditors.ts b/src/vs/workbench/api/node/extHostTextEditors.ts index 0e4920634b9..1513b330270 100644 --- a/src/vs/workbench/api/node/extHostTextEditors.ts +++ b/src/vs/workbench/api/node/extHostTextEditors.ts @@ -123,7 +123,7 @@ export class ExtHostEditors implements ExtHostEditorsShape { textEditor._acceptOptions(data.options); } if (data.selections) { - const selections = data.selections.selections.map(TypeConverters.toSelection); + const selections = data.selections.selections.map(TypeConverters.Selection.to); textEditor._acceptSelections(selections); } if (data.visibleRanges) { @@ -140,7 +140,7 @@ export class ExtHostEditors implements ExtHostEditorsShape { } if (data.selections) { const kind = TextEditorSelectionChangeKind.fromValue(data.selections.source); - const selections = data.selections.selections.map(TypeConverters.toSelection); + const selections = data.selections.selections.map(TypeConverters.Selection.to); this._onDidChangeTextEditorSelection.fire({ textEditor, selections, diff --git a/src/vs/workbench/api/node/extHostTypeConverters.ts b/src/vs/workbench/api/node/extHostTypeConverters.ts index 78116fe3a5a..7c7992788a4 100644 --- a/src/vs/workbench/api/node/extHostTypeConverters.ts +++ b/src/vs/workbench/api/node/extHostTypeConverters.ts @@ -36,22 +36,24 @@ export interface SelectionLike extends RangeLike { anchor: PositionLike; active: PositionLike; } +export namespace Selection { -export function toSelection(selection: ISelection): types.Selection { - let { selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn } = selection; - let start = new types.Position(selectionStartLineNumber - 1, selectionStartColumn - 1); - let end = new types.Position(positionLineNumber - 1, positionColumn - 1); - return new types.Selection(start, end); -} + export function to(selection: ISelection): types.Selection { + let { selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn } = selection; + let start = new types.Position(selectionStartLineNumber - 1, selectionStartColumn - 1); + let end = new types.Position(positionLineNumber - 1, positionColumn - 1); + return new types.Selection(start, end); + } -export function fromSelection(selection: SelectionLike): ISelection { - let { anchor, active } = selection; - return { - selectionStartLineNumber: anchor.line + 1, - selectionStartColumn: anchor.character + 1, - positionLineNumber: active.line + 1, - positionColumn: active.character + 1 - }; + export function from(selection: SelectionLike): ISelection { + let { anchor, active } = selection; + return { + selectionStartLineNumber: anchor.line + 1, + selectionStartColumn: anchor.character + 1, + positionLineNumber: active.line + 1, + positionColumn: active.character + 1 + }; + } } export function fromRange(range: RangeLike): IRange {