提交 95fc0327 编写于 作者: J Joel Day

TextEditor.edit snippet overload now returns void. No longer preventing when...

TextEditor.edit snippet overload now returns void. No longer preventing when already in snippet mode.
上级 713aaff9
...@@ -41,8 +41,9 @@ suite('editor tests', () => { ...@@ -41,8 +41,9 @@ suite('editor tests', () => {
.appendText(' snippet'); .appendText(' snippet');
return withRandomFileEditor('', (editor, doc) => { return withRandomFileEditor('', (editor, doc) => {
return editor.edit(snippetString).then(inserted => { editor.edit(snippetString);
assert.ok(inserted);
return editor.edit(() => {}).then(() => {
assert.equal(doc.getText(), 'This is a placeholder snippet'); assert.equal(doc.getText(), 'This is a placeholder snippet');
assert.ok(doc.isDirty); assert.ok(doc.isDirty);
}); });
...@@ -59,8 +60,9 @@ suite('editor tests', () => { ...@@ -59,8 +60,9 @@ suite('editor tests', () => {
new Position(0, 12) new Position(0, 12)
); );
return editor.edit(snippetString).then(inserted => { editor.edit(snippetString);
assert.ok(inserted);
return editor.edit(() => {}).then(() => {
assert.equal(doc.getText(), 'This has been replaced'); assert.equal(doc.getText(), 'This has been replaced');
assert.ok(doc.isDirty); assert.ok(doc.isDirty);
}); });
......
...@@ -467,10 +467,6 @@ export class SnippetController { ...@@ -467,10 +467,6 @@ export class SnippetController {
return SnippetController.ID; return SnippetController.ID;
} }
public get inSnippetMode() {
return this._inSnippetMode.get();
}
public insertSnippet(template: string, overwriteBefore: number, overwriteAfter: number): void { public insertSnippet(template: string, overwriteBefore: number, overwriteAfter: number): void {
const snippet = CodeSnippet.fromTextmate(template, this._variableResolver); const snippet = CodeSnippet.fromTextmate(template, this._variableResolver);
this.run(snippet, overwriteBefore, overwriteAfter); this.run(snippet, overwriteBefore, overwriteAfter);
......
...@@ -939,11 +939,10 @@ declare module 'vscode' { ...@@ -939,11 +939,10 @@ declare module 'vscode' {
/** /**
* Enters snippet mode in the editor with the specified snippet. * 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. * @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 * Adds a set of decorations to the text editor. If a set of decorations already exists with
......
...@@ -112,11 +112,11 @@ declare module 'vscode' { ...@@ -112,11 +112,11 @@ declare module 'vscode' {
/** /**
* Enters snippet mode in the editor with the specified snippet. * 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. * @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 { export interface SCMResourceThemableDecorations {
......
...@@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape { ...@@ -137,7 +137,7 @@ export abstract class MainThreadEditorsShape {
$tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise<any> { throw ni(); } $tryRevealRange(id: string, range: editorCommon.IRange, revealType: TextEditorRevealType): TPromise<any> { throw ni(); }
$trySetSelections(id: string, selections: editorCommon.ISelection[]): 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(); } $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 { export abstract class MainThreadTreeExplorersShape {
......
...@@ -596,11 +596,11 @@ class ExtHostTextEditor implements vscode.TextEditor { ...@@ -596,11 +596,11 @@ class ExtHostTextEditor implements vscode.TextEditor {
// ---- editing // ---- editing
edit(callback: (edit: TextEditorEdit) => void, options: { undoStopBefore: boolean; undoStopAfter: boolean; }): Thenable<boolean>; 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)) { if (SnippetString.isSnippetString(callbackOrSnippet)) {
return this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options); this._proxy.$tryInsertSnippet(this._id, callbackOrSnippet.value, options);
} else { } else {
let edit = new TextEditorEdit(this._documentData.document, options); let edit = new TextEditorEdit(this._documentData.document, options);
callbackOrSnippet(edit); callbackOrSnippet(edit);
......
...@@ -293,11 +293,12 @@ export class MainThreadEditors extends MainThreadEditorsShape { ...@@ -293,11 +293,12 @@ export class MainThreadEditors extends MainThreadEditorsShape {
return TPromise.as(this._textEditorsMap[id].applyEdits(modelVersionId, edits, opts)); 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]) { if (!this._textEditorsMap[id]) {
return TPromise.wrapError('TextEditor disposed'); 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 { $registerTextEditorDecorationType(key: string, options: IDecorationRenderOptions): void {
......
...@@ -394,9 +394,6 @@ export class MainThreadTextEditor { ...@@ -394,9 +394,6 @@ export class MainThreadTextEditor {
insertSnippet(template: string, opts: IInsertSnippetOptions) { insertSnippet(template: string, opts: IInsertSnippetOptions) {
const snippetController = SnippetController.get(this._codeEditor); const snippetController = SnippetController.get(this._codeEditor);
if (snippetController.inSnippetMode) {
return false;
}
this._codeEditor.focus(); this._codeEditor.focus();
...@@ -409,8 +406,6 @@ export class MainThreadTextEditor { ...@@ -409,8 +406,6 @@ export class MainThreadTextEditor {
if (opts.undoStopAfter) { if (opts.undoStopAfter) {
this._codeEditor.pushUndoStop(); this._codeEditor.pushUndoStop();
} }
return true;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册