mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-12 20:12:23 +01:00
TextEditor.edit snippet overload now returns void. No longer preventing when already in snippet mode.
This commit is contained in:
@@ -41,8 +41,9 @@ suite('editor tests', () => {
|
||||
.appendText(' snippet');
|
||||
|
||||
return withRandomFileEditor('', (editor, doc) => {
|
||||
return editor.edit(snippetString).then(inserted => {
|
||||
assert.ok(inserted);
|
||||
editor.edit(snippetString);
|
||||
|
||||
return editor.edit(() => {}).then(() => {
|
||||
assert.equal(doc.getText(), 'This is a placeholder snippet');
|
||||
assert.ok(doc.isDirty);
|
||||
});
|
||||
@@ -59,8 +60,9 @@ suite('editor tests', () => {
|
||||
new Position(0, 12)
|
||||
);
|
||||
|
||||
return editor.edit(snippetString).then(inserted => {
|
||||
assert.ok(inserted);
|
||||
editor.edit(snippetString);
|
||||
|
||||
return editor.edit(() => {}).then(() => {
|
||||
assert.equal(doc.getText(), 'This has been replaced');
|
||||
assert.ok(doc.isDirty);
|
||||
});
|
||||
|
||||
@@ -467,10 +467,6 @@ export class SnippetController {
|
||||
return SnippetController.ID;
|
||||
}
|
||||
|
||||
public get inSnippetMode() {
|
||||
return this._inSnippetMode.get();
|
||||
}
|
||||
|
||||
public insertSnippet(template: string, overwriteBefore: number, overwriteAfter: number): void {
|
||||
const snippet = CodeSnippet.fromTextmate(template, this._variableResolver);
|
||||
this.run(snippet, overwriteBefore, overwriteAfter);
|
||||
|
||||
Vendored
+2
-3
@@ -939,11 +939,10 @@ declare module 'vscode' {
|
||||
/**
|
||||
* Enters snippet mode in the editor with the specified snippet.
|
||||
*
|
||||
* @param snippet The snippet to insert
|
||||
* @param snippet The snippet to insert in this edit.
|
||||
* @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 editor entered snippet mode.
|
||||
*/
|
||||
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
|
||||
|
||||
/**
|
||||
* Adds a set of decorations to the text editor. If a set of decorations already exists with
|
||||
|
||||
Vendored
+3
-3
@@ -112,11 +112,11 @@ declare module 'vscode' {
|
||||
/**
|
||||
* Enters snippet mode in the editor with the specified snippet.
|
||||
*
|
||||
* @param snippet The snippet to insert
|
||||
* @param snippet The snippet to insert in this edit.
|
||||
* @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 editor entered snippet mode.
|
||||
*/
|
||||
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>;
|
||||
edit(snippet: SnippetString, options?: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
|
||||
|
||||
}
|
||||
|
||||
export interface SCMResourceThemableDecorations {
|
||||
|
||||
@@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape {
|
||||
$tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise<any> { throw ni(); }
|
||||
$trySetSelections(id: string, selections: editorCommon.ISelection[]): TPromise<any> { throw ni(); }
|
||||
$tryApplyEdits(id: string, modelVersionId: number, edits: editorCommon.ISingleEditOperation[], opts: IApplyEditsOptions): TPromise<boolean> { throw ni(); }
|
||||
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<boolean> { throw ni(); }
|
||||
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<any> { throw ni(); }
|
||||
}
|
||||
|
||||
export abstract class MainThreadTreeExplorersShape {
|
||||
|
||||
@@ -596,11 +596,11 @@ 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(snippet: SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): void;
|
||||
|
||||
edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> {
|
||||
edit(callbackOrSnippet: ((edit: TextEditorEdit) => void) | SnippetString, options: { undoStopBefore: boolean; undoStopAfter: boolean; } = { undoStopBefore: true, undoStopAfter: true }): Thenable<boolean> | void {
|
||||
if (SnippetString.isSnippetString(callbackOrSnippet)) {
|
||||
return this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
|
||||
this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
|
||||
} else {
|
||||
let edit = new TextEditorEdit(this._documentData.document, options);
|
||||
callbackOrSnippet(edit);
|
||||
|
||||
@@ -293,11 +293,12 @@ export class MainThreadEditors extends MainThreadEditorsShape {
|
||||
return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits, opts));
|
||||
}
|
||||
|
||||
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<boolean> {
|
||||
$tryInsertSnippet(id: string, template: string, opts: IInsertSnippetOptions): TPromise<any> {
|
||||
if (!this._textEditorsMap[id]) {
|
||||
return TPromise.wrapError('TextEditor disposed');
|
||||
}
|
||||
return TPromise.as(this._textEditorsMap[id].insertSnippet(template, opts));
|
||||
this._textEditorsMap[id].insertSnippet(template, opts);
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
$registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void {
|
||||
|
||||
@@ -394,9 +394,6 @@ export class MainThreadTextEditor {
|
||||
|
||||
insertSnippet(template: string, opts: IInsertSnippetOptions) {
|
||||
const snippetController = SnippetController.get(this._codeEditor);
|
||||
if (snippetController.inSnippetMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._codeEditor.focus();
|
||||
|
||||
@@ -409,8 +406,6 @@ export class MainThreadTextEditor {
|
||||
if (opts.undoStopAfter) {
|
||||
this._codeEditor.pushUndoStop();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user