diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts index c54a16efa622f..5fe866a59fdb3 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffEditor.ts @@ -27,7 +27,7 @@ import { PixelRatio } from 'vs/base/browser/pixelRatio'; import { CellEditState, ICellOutputViewModel, IDisplayOutputLayoutUpdateRequest, IGenericCellViewModel, IInsetRenderOutput, INotebookEditorCreationOptions, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; import { DiffSide, DIFF_CELL_MARGIN, IDiffCellInfo, INotebookTextDiffEditor, INotebookDiffViewModel } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser'; import { Emitter, Event } from 'vs/base/common/event'; -import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; +import { DisposableStore, dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane'; import { CellUri, INotebookDiffEditorModel, INotebookDiffResult, NOTEBOOK_DIFF_EDITOR_ID, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { URI } from 'vs/base/common/uri'; @@ -568,7 +568,9 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD NotebookTextDiffEditor.prettyChanges(this._model, diffResult.cellsDiff); const { viewModels, firstChangeIndex } = NotebookTextDiffEditor.computeDiff(this.instantiationService, this.configurationService, this._model, this._eventDispatcher!, diffResult, this.fontInfo); - if (!this.notebookDiffViewModel.isEqual(viewModels)) { + if (this.notebookDiffViewModel.isEqual(viewModels)) { + dispose(viewModels); + } else { this._originalWebview?.removeInsets([...this._originalWebview?.insetMapping.keys()]); this._modifiedWebview?.removeInsets([...this._modifiedWebview?.insetMapping.keys()]); this.notebookDiffViewModel.setViewModel(viewModels); diff --git a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts index f2ecb1b07c480..8e1f6d95c2021 100644 --- a/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts +++ b/src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts @@ -24,6 +24,7 @@ export class NotebookDiffViewModel extends Disposable implements INotebookDiffVi super.dispose(); } clear() { + this.disposables.clear(); dispose(Array.from(this.placeholderAndRelatedCells.keys())); this.placeholderAndRelatedCells.clear(); dispose(this.originalCellViewModels); @@ -33,8 +34,8 @@ export class NotebookDiffViewModel extends Disposable implements INotebookDiffVi } setViewModel(cellViewModels: DiffElementCellViewModelBase[]) { - this.disposables.clear(); const oldLength = this._items.length; + this.clear(); this._items.splice(0, oldLength); let placeholder: DiffElementPlaceholderViewModel | undefined = undefined;