Update decorators when model changes

don/notebookChatEdits14
Don Jayamanne 2024-11-16 15:42:23 +11:00
parent 9dc32500f5
commit 05e7215296
No known key found for this signature in database
GPG Key ID: 6E3F5E00E1354B5F
1 changed files with 13 additions and 23 deletions

View File

@ -50,6 +50,7 @@ export class NotebookCellDiffDecorator extends DisposableStore {
) {
super();
this.add(this.editor.onDidChangeModel(() => this.update()));
this.add(this.editor.onDidChangeModelContent(() => this.update()));
this.add(this.editor.onDidChangeConfiguration((e) => {
if (e.hasChanged(EditorOption.fontInfo) || e.hasChanged(EditorOption.lineHeight)) {
this.update();
@ -105,10 +106,6 @@ export class NotebookCellDiffDecorator extends DisposableStore {
if (this.isDisposed) {
return;
}
if (!this.editor.hasModel()) {
this._clearRendering();
return;
}
if (this.editor.getOption(EditorOption.inDiffEditor)) {
this._clearRendering();
return;
@ -119,9 +116,19 @@ export class NotebookCellDiffDecorator extends DisposableStore {
return;
}
const version = model.getVersionId();
const originalModel = this.getOrCreateOriginalModel();
const diff = originalModel ? await this.computeDiff() : undefined;
if (!originalModel) {
this._clearRendering();
return;
}
const version = model.getVersionId();
const diff = await this._editorWorkerService.computeDiff(
originalModel.uri,
model.uri,
{ computeMoves: true, ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER },
'advanced'
);
if (this.isDisposed) {
return;
}
@ -154,23 +161,6 @@ export class NotebookCellDiffDecorator extends DisposableStore {
}
return this._originalModel;
}
private async computeDiff() {
const model = this.editor.getModel();
if (!model) {
return;
}
const originalModel = this.getOrCreateOriginalModel();
if (!originalModel) {
return;
}
return this._editorWorkerService.computeDiff(
originalModel.uri,
model.uri,
{ computeMoves: true, ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER },
'advanced'
);
}
private _updateWithDiff(originalModel: ITextModel | undefined, diff: IDocumentDiff): void {
const chatDiffAddDecoration = ModelDecorationOptions.createDynamic({