提交 43b7437a 编写于 作者: S Sandeep Somavarapu

Folding: Compute collapsible region immediately when editor model changes

上级 72dfd0e1
...@@ -189,53 +189,31 @@ export class FoldingController implements editorCommon.IEditorContribution { ...@@ -189,53 +189,31 @@ export class FoldingController implements editorCommon.IEditorContribution {
return; return;
} }
this.contentChangedScheduler = new RunOnceScheduler(() => { this.computeAndApplyCollapsibleRegions();
let myToken = (++this.computeToken); this.contentChangedScheduler = new RunOnceScheduler(() => this.computeAndApplyCollapsibleRegions(), 200);
this.cursorChangedScheduler = new RunOnceScheduler(() => this.revealCursor(), 200);
this.computeCollapsibleRegions().then(regions => {
if (myToken !== this.computeToken) {
return; // A new request was made in the meantime or the model was changed
}
this.applyRegions(regions);
});
}, 200);
this.cursorChangedScheduler = new RunOnceScheduler(() => {
this.revealCursor();
}, 200);
this.localToDispose.push(this.contentChangedScheduler); this.localToDispose.push(this.contentChangedScheduler);
this.localToDispose.push(this.cursorChangedScheduler); this.localToDispose.push(this.cursorChangedScheduler);
this.localToDispose.push(this.editor.onDidChangeModelContent(() => {
this.contentChangedScheduler.schedule();
}));
this.localToDispose.push({
dispose: () => {
++this.computeToken;
this.editor.changeDecorations(changeAccessor => {
this.decorations.forEach(dec => dec.dispose(changeAccessor));
}); this.localToDispose.push(this.editor.onDidChangeModelContent(e => this.contentChangedScheduler.schedule()));
this.decorations = []; this.localToDispose.push(this.editor.onDidChangeCursorPosition(e => this.cursorChangedScheduler.schedule()));
this.editor.setHiddenAreas([]);
}
});
this.localToDispose.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e))); this.localToDispose.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e)));
this.localToDispose.push(this.editor.onMouseUp(e => this.onEditorMouseUp(e))); this.localToDispose.push(this.editor.onMouseUp(e => this.onEditorMouseUp(e)));
this.localToDispose.push(this.editor.onDidChangeCursorPosition(e => {
this.cursorChangedScheduler.schedule();
}));
this.contentChangedScheduler.schedule(); this.localToDispose.push({ dispose: () => this.disposeDecorations() });
} }
private computeCollapsibleRegions(): TPromise<IFoldingRange[]> { private computeAndApplyCollapsibleRegions(): void {
let model = this.editor.getModel(); let model = this.editor.getModel();
if (!model) { this.applyRegions(model ? computeRanges(model) : []);
return TPromise.as([]); }
}
let ranges = computeRanges(model); private disposeDecorations() {
return TPromise.as(ranges); this.editor.changeDecorations(changeAccessor => {
this.decorations.forEach(dec => dec.dispose(changeAccessor));
});
this.decorations = [];
this.editor.setHiddenAreas([]);
} }
private revealCursor() { private revealCursor() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册