Skip to content

Commit 2c42d6a

Browse files
authored
Update decorators when model contents change (microsoft#233970)
1 parent 0c7c759 commit 2c42d6a

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/vs/workbench/contrib/notebook/browser/chatEdit/notebookCellDecorators.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class NotebookCellDiffDecorator extends DisposableStore {
5050
) {
5151
super();
5252
this.add(this.editor.onDidChangeModel(() => this.update()));
53+
this.add(this.editor.onDidChangeModelContent(() => this.update()));
5354
this.add(this.editor.onDidChangeConfiguration((e) => {
5455
if (e.hasChanged(EditorOption.fontInfo) || e.hasChanged(EditorOption.lineHeight)) {
5556
this.update();
@@ -105,10 +106,6 @@ export class NotebookCellDiffDecorator extends DisposableStore {
105106
if (this.isDisposed) {
106107
return;
107108
}
108-
if (!this.editor.hasModel()) {
109-
this._clearRendering();
110-
return;
111-
}
112109
if (this.editor.getOption(EditorOption.inDiffEditor)) {
113110
this._clearRendering();
114111
return;
@@ -119,9 +116,19 @@ export class NotebookCellDiffDecorator extends DisposableStore {
119116
return;
120117
}
121118

122-
const version = model.getVersionId();
123119
const originalModel = this.getOrCreateOriginalModel();
124-
const diff = originalModel ? await this.computeDiff() : undefined;
120+
if (!originalModel) {
121+
this._clearRendering();
122+
return;
123+
}
124+
const version = model.getVersionId();
125+
const diff = await this._editorWorkerService.computeDiff(
126+
originalModel.uri,
127+
model.uri,
128+
{ computeMoves: true, ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER },
129+
'advanced'
130+
);
131+
125132
if (this.isDisposed) {
126133
return;
127134
}
@@ -154,23 +161,6 @@ export class NotebookCellDiffDecorator extends DisposableStore {
154161
}
155162
return this._originalModel;
156163
}
157-
private async computeDiff() {
158-
const model = this.editor.getModel();
159-
if (!model) {
160-
return;
161-
}
162-
const originalModel = this.getOrCreateOriginalModel();
163-
if (!originalModel) {
164-
return;
165-
}
166-
167-
return this._editorWorkerService.computeDiff(
168-
originalModel.uri,
169-
model.uri,
170-
{ computeMoves: true, ignoreTrimWhitespace: false, maxComputationTimeMs: Number.MAX_SAFE_INTEGER },
171-
'advanced'
172-
);
173-
}
174164

175165
private _updateWithDiff(originalModel: ITextModel | undefined, diff: IDocumentDiff): void {
176166
const chatDiffAddDecoration = ModelDecorationOptions.createDynamic({

0 commit comments

Comments
 (0)