mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-13 15:35:20 +01:00
explicit insertSnippet function instead of edit overload, #19116
This commit is contained in:
@@ -41,7 +41,7 @@ suite('editor tests', () => {
|
||||
.appendText(' snippet');
|
||||
|
||||
return withRandomFileEditor('', (editor, doc) => {
|
||||
return editor.edit(snippetString).then(inserted => {
|
||||
return editor.insertSnippet(snippetString).then(inserted => {
|
||||
assert.ok(inserted);
|
||||
assert.equal(doc.getText(), 'This is a placeholder snippet');
|
||||
assert.ok(doc.isDirty);
|
||||
@@ -59,7 +59,7 @@ suite('editor tests', () => {
|
||||
new Position(0, 12)
|
||||
);
|
||||
|
||||
return editor.edit(snippetString).then(inserted => {
|
||||
return editor.insertSnippet(snippetString).then(inserted => {
|
||||
assert.ok(inserted);
|
||||
assert.equal(doc.getText(), 'This has been replaced');
|
||||
assert.ok(doc.isDirty);
|
||||
|
||||
Vendored
+1
-1
@@ -947,7 +947,7 @@ declare module 'vscode' {
|
||||
* @param options The undo/redo behaviour around this edit. By default, undo stops will be created before and after this edit.
|
||||
* @return A promise that resolves with a value indicating if the snippet could be inserted.
|
||||
*/
|
||||
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
insertSnippet(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
|
||||
/**
|
||||
* Adds a set of decorations to the text editor. If a set of decorations already exists with
|
||||
|
||||
@@ -595,17 +595,10 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
|
||||
// ---- editing
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
_applyEdit(editBuilder: TextEditorEdit): TPromise<boolean> {
|
||||
@@ -627,6 +620,10 @@ class ExtHostTextEditor implements vscode.TextEditor {
|
||||
});
|
||||
}
|
||||
|
||||
insertSnippet(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
return this._proxy.$tryInsertSnippet(this._id, snippet.value, options);
|
||||
}
|
||||
|
||||
// ---- util
|
||||
|
||||
private _runOnProxy(callback: () => TPromise<any>, silent: boolean): TPromise<ExtHostTextEditor> {
|
||||
|
||||
Reference in New Issue
Block a user