提交 df322e68 编写于 作者: J Johannes Rieken

debt - less winjs.promise

上级 7452fe03
......@@ -20,6 +20,8 @@ import { registerThemingParticipant } from 'vs/platform/theme/common/themeServic
import { editorBracketMatchBorder } from 'vs/editor/common/view/editorColorRegistry';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { CancelablePromise, createCancelablePromise, timeout } from 'vs/base/common/async';
import { onUnexpectedError } from 'vs/base/common/errors';
class InPlaceReplaceController implements IEditorContribution {
......@@ -33,11 +35,11 @@ class InPlaceReplaceController implements IEditorContribution {
className: 'valueSetReplacement'
});
private editor: ICodeEditor;
private currentRequest: TPromise<IInplaceReplaceSupportResult>;
private decorationRemover: TPromise<void>;
private decorationIds: string[];
private editorWorkerService: IEditorWorkerService;
private readonly editor: ICodeEditor;
private readonly editorWorkerService: IEditorWorkerService;
private decorationIds: string[] = [];
private currentRequest: CancelablePromise<IInplaceReplaceSupportResult>;
private decorationRemover: CancelablePromise<void>;
constructor(
editor: ICodeEditor,
......@@ -45,9 +47,6 @@ class InPlaceReplaceController implements IEditorContribution {
) {
this.editor = editor;
this.editorWorkerService = editorWorkerService;
this.currentRequest = TPromise.as(<IInplaceReplaceSupportResult>null);
this.decorationRemover = TPromise.as(<void>null);
this.decorationIds = [];
}
public dispose(): void {
......@@ -57,10 +56,12 @@ class InPlaceReplaceController implements IEditorContribution {
return InPlaceReplaceController.ID;
}
public run(source: string, up: boolean): TPromise<void> {
public run(source: string, up: boolean): Thenable<void> {
// cancel any pending request
this.currentRequest.cancel();
if (this.currentRequest) {
this.currentRequest.cancel();
}
let selection = this.editor.getSelection();
const model = this.editor.getModel();
......@@ -74,18 +75,12 @@ class InPlaceReplaceController implements IEditorContribution {
const state = new EditorState(this.editor, CodeEditorStateFlag.Value | CodeEditorStateFlag.Position);
if (!this.editorWorkerService.canNavigateValueSet(modelURI)) {
this.currentRequest = TPromise.as(null);
} else {
this.currentRequest = this.editorWorkerService.navigateValueSet(modelURI, selection, up);
this.currentRequest = this.currentRequest.then((basicResult) => {
if (basicResult && basicResult.range && basicResult.value) {
return basicResult;
}
return null;
});
return undefined;
}
return this.currentRequest.then((result: IInplaceReplaceSupportResult) => {
this.currentRequest = createCancelablePromise(token => this.editorWorkerService.navigateValueSet(modelURI, selection, up));
return this.currentRequest.then(result => {
if (!result || !result.range || !result.value) {
// No proper result
......@@ -127,12 +122,13 @@ class InPlaceReplaceController implements IEditorContribution {
}]);
// remove decoration after delay
this.decorationRemover.cancel();
this.decorationRemover = TPromise.timeout(350);
this.decorationRemover.then(() => {
this.decorationIds = this.editor.deltaDecorations(this.decorationIds, []);
});
});
if (this.decorationRemover) {
this.decorationRemover.cancel();
}
this.decorationRemover = timeout(350);
this.decorationRemover.then(() => this.decorationIds = this.editor.deltaDecorations(this.decorationIds, [])).catch(onUnexpectedError);
}).catch(onUnexpectedError);
}
}
......@@ -156,7 +152,7 @@ class InPlaceReplaceUp extends EditorAction {
if (!controller) {
return undefined;
}
return controller.run(this.id, true);
return TPromise.wrap(controller.run(this.id, true));
}
}
......@@ -180,7 +176,7 @@ class InPlaceReplaceDown extends EditorAction {
if (!controller) {
return undefined;
}
return controller.run(this.id, false);
return TPromise.wrap(controller.run(this.id, false));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册