mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Insert snippet API changes.
This commit is contained in:
@@ -12,8 +12,8 @@ import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ExtHostDocuments, ExtHostDocumentData } from 'vs/workbench/api/node/extHostDocuments';
|
||||
import { Selection, Range, Position, EndOfLine, TextEditorRevealType, TextEditorSelectionChangeKind, TextEditorLineNumbersStyle } from './extHostTypes';
|
||||
import { ISingleEditOperation, TextEditorCursorStyle, IPosition, IRange } from 'vs/editor/common/editorCommon';
|
||||
import { Selection, Range, Position, EndOfLine, TextEditorRevealType, TextEditorSelectionChangeKind, TextEditorLineNumbersStyle, SnippetString } from './extHostTypes';
|
||||
import { ISingleEditOperation, TextEditorCursorStyle } from 'vs/editor/common/editorCommon';
|
||||
import { IResolvedTextEditorConfiguration, ISelectionChangeEvent, ITextEditorConfigurationUpdate } from 'vs/workbench/api/node/mainThreadEditorsTracker';
|
||||
import * as TypeConverters from './extHostTypeConverters';
|
||||
import { MainContext, MainThreadEditorsShape, ExtHostEditorsShape, ITextEditorAddData, ITextEditorPositionData } from './extHost.protocol';
|
||||
@@ -595,10 +595,17 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
// ---- editing
|
||||
|
||||
edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
let edit = new TextEditorEdit(this._documentData.document, options);
|
||||
callback(edit);
|
||||
return this._applyEdit(edit);
|
||||
edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
edit(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
|
||||
edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
if (SnippetString.isSnippetString(callbackOrSnippet)) {
|
||||
return this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
|
||||
} else {
|
||||
let edit = new TextEditorEdit(this._documentData.document, options);
|
||||
callbackOrSnippet(edit);
|
||||
return this._applyEdit(edit);
|
||||
}
|
||||
}
|
||||
|
||||
_applyEdit(editBuilder: TextEditorEdit): TPromise<boolean> {
|
||||
@@ -620,22 +627,6 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
});
|
||||
}
|
||||
|
||||
insertSnippet(template: string, posOrRange: Position | Range) {
|
||||
let convertedPosOrRange: IPosition | IRange;
|
||||
|
||||
if (Position.isPosition(posOrRange)) {
|
||||
convertedPosOrRange = TypeConverters.fromPosition(posOrRange);
|
||||
}
|
||||
else if (Range.isRange(posOrRange)) {
|
||||
convertedPosOrRange = TypeConverters.fromRange(posOrRange);
|
||||
}
|
||||
else {
|
||||
return TPromise.wrapError(new Error('Unrecognized value for posOrRange'));
|
||||
}
|
||||
|
||||
return this._proxy.$tryInsertSnippet(this._id, template, convertedPosOrRange);
|
||||
}
|
||||
|
||||
// ---- util
|
||||
|
||||
private _runOnProxy(callback: () => TPromise<any>, silent: boolean): TPromise<ExtHostTextEditor> {
|
||||
|
||||
Reference in New Issue
Block a user