From 0d652274ded865d144141f8fafad82d19af4e209 Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Thu, 30 Jul 2026 11:06:22 +0000 Subject: [PATCH] fix: dispose removed notebook cell view models --- .../viewModel/notebookViewModelImpl.ts | 2 +- .../test/browser/notebookViewModel.test.ts | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts index 52892c1e43b5ea..d3c7c9e8c9ed67 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewModel/notebookViewModelImpl.ts @@ -225,7 +225,7 @@ export class NotebookViewModel extends Disposable implements EditorFoldingStateD deletedCells.forEach(cell => { this._handleToViewCellMapping.delete(cell.handle); // dispose the cell to release ref to the cell text document - cell.dispose(); + this._localStore.delete(cell); }); diff[2].forEach(cell => { diff --git a/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts b/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts index 44c613b094fdb7..58f54d66fa2a46 100644 --- a/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts +++ b/src/vs/workbench/contrib/notebook/test/browser/notebookViewModel.test.ts @@ -104,6 +104,32 @@ suite('NotebookViewModel', () => { ); }); + test('deleted cells are removed from the disposable store', async function () { + const getDisposeCallCount = await withTestNotebook( + [ + ['var a = 1;', 'javascript', CellKind.Code, [], {}], + ['var b = 2;', 'javascript', CellKind.Code, [], {}] + ], + (editor, viewModel) => { + const cell = insertCellAtIndex(viewModel, 1, 'var c = 3', 'javascript', CellKind.Code, {}, [], true, true); + const originalDispose = cell.dispose.bind(cell); + let disposeCallCount = 0; + cell.dispose = () => { + disposeCallCount++; + originalDispose(); + }; + + runDeleteAction(editor, cell); + assert.strictEqual(disposeCallCount, 1); + cell.model.dispose(); + + return () => disposeCallCount; + } + ); + + assert.strictEqual(getDisposeCallCount(), 1); + }); + test('index', async function () { await withTestNotebook( [