mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
type converters, use namespace for Selection
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -474,7 +474,7 @@ export class ExtHostTextEditor implements vscode.TextEditor {
|
||||
}
|
||||
|
||||
private _trySetSelection(): TPromise<vscode.TextEditor> {
|
||||
let selection = this._selections.map(TypeConverters.fromSelection);
|
||||
let selection = this._selections.map(TypeConverters.Selection.from);
|
||||
return this._runOnProxy(() => this._proxy.$trySetSelections(this._id, selection));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user