diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/scm/scm.ts b/src/vs/workbench/contrib/notebook/browser/contrib/scm/scm.ts index e43a7a8ba74..3b3601c8d7f 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/scm/scm.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/scm/scm.ts @@ -4,14 +4,12 @@ *--------------------------------------------------------------------------------------------*/ import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; -import { INotebookEditorContribution, INotebookEditor, INotebookDeltaDecoration } from '../../notebookBrowser'; +import { INotebookEditorContribution, INotebookEditor } from '../../notebookBrowser'; import { registerNotebookContribution } from '../../notebookEditorExtensions'; import { ISCMService } from 'vs/workbench/contrib/scm/common/scm'; import { createProviderComparer } from 'vs/workbench/contrib/scm/browser/dirtydiffDecorator'; import { first, ThrottledDelayer } from 'vs/base/common/async'; import { INotebookService } from '../../../common/notebookService'; -import { LcsDiff } from 'vs/base/common/diff/diff'; -import { CellSequence } from 'vs/workbench/contrib/notebook/common/notebookCommon'; import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel'; import { FileService } from 'vs/platform/files/common/fileService'; import { IFileService } from 'vs/platform/files/common/files'; @@ -40,6 +38,7 @@ export class SCMController extends Disposable implements INotebookEditorContribu if (!this._notebookEditor.isEmbedded) { this._register(this._notebookEditor.onDidChangeModel(() => { this._localDisposable.clear(); + this._originalResourceDisposableStore.clear(); this._diffDelayer.cancel(); this.update(); @@ -54,6 +53,11 @@ export class SCMController extends Disposable implements INotebookEditorContribu } })); + this._register(this._notebookEditor.onWillDispose(() => { + this._localDisposable.clear(); + this._originalResourceDisposableStore.clear(); + })); + this.update(); } } @@ -87,6 +91,12 @@ export class SCMController extends Disposable implements INotebookEditorContribu })); const originalDocument = await this._notebookService.resolveNotebook(viewType, result, false); + this._originalResourceDisposableStore.add({ + dispose: () => { + this._originalDocument?.dispose(); + this._originalDocument = undefined; + } + }); this._originalDocument = originalDocument; } @@ -115,37 +125,37 @@ export class SCMController extends Disposable implements INotebookEditorContribu return; } - const diff = new LcsDiff(new CellSequence(this._originalDocument), new CellSequence(modifiedDocument)); - const diffResult = diff.ComputeDiff(false); + // const diff = new LcsDiff(new CellSequence(this._originalDocument), new CellSequence(modifiedDocument)); + // const diffResult = diff.ComputeDiff(false); - const decorations: INotebookDeltaDecoration[] = []; - diffResult.changes.forEach(change => { - if (change.originalLength === 0) { - // doesn't exist in original - for (let i = 0; i < change.modifiedLength; i++) { - decorations.push({ - handle: modifiedDocument.cells[change.modifiedStart + i].handle, - options: { gutterClassName: 'nb-gutter-cell-inserted' } - }); - } - } else { - if (change.modifiedLength === 0) { - // diff.deleteCount - // removed from original - } else { - // modification - for (let i = 0; i < change.modifiedLength; i++) { - decorations.push({ - handle: modifiedDocument.cells[change.modifiedStart + i].handle, - options: { gutterClassName: 'nb-gutter-cell-changed' } - }); - } - } - } - }); + // const decorations: INotebookDeltaDecoration[] = []; + // diffResult.changes.forEach(change => { + // if (change.originalLength === 0) { + // // doesn't exist in original + // for (let i = 0; i < change.modifiedLength; i++) { + // decorations.push({ + // handle: modifiedDocument.cells[change.modifiedStart + i].handle, + // options: { gutterClassName: 'nb-gutter-cell-inserted' } + // }); + // } + // } else { + // if (change.modifiedLength === 0) { + // // diff.deleteCount + // // removed from original + // } else { + // // modification + // for (let i = 0; i < change.modifiedLength; i++) { + // decorations.push({ + // handle: modifiedDocument.cells[change.modifiedStart + i].handle, + // options: { gutterClassName: 'nb-gutter-cell-changed' } + // }); + // } + // } + // } + // }); - this._lastDecorationId = this._notebookEditor.deltaCellDecorations(this._lastDecorationId, decorations); + // this._lastDecorationId = this._notebookEditor.deltaCellDecorations(this._lastDecorationId, decorations); }); } diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index 036df080c73..6f0d4cba56b 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -56,7 +56,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/format/formatting'; import 'vs/workbench/contrib/notebook/browser/contrib/toc/tocProvider'; import 'vs/workbench/contrib/notebook/browser/contrib/marker/markerProvider'; import 'vs/workbench/contrib/notebook/browser/contrib/status/editorStatus'; -import 'vs/workbench/contrib/notebook/browser/contrib/scm/scm'; +// import 'vs/workbench/contrib/notebook/browser/contrib/scm/scm'; // Output renderers registration diff --git a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts index 32afacda32c..d7c106c9531 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts @@ -224,6 +224,7 @@ export interface INotebookEditor extends IEditor { readonly onDidChangeKernel: Event; readonly onDidChangeActiveCell: Event; readonly onDidScroll: Event; + readonly onWillDispose: Event; isDisposed: boolean; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts index 7a2a854f4e0..fc26daa688a 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts @@ -101,6 +101,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor public readonly onDidFocus = this._onDidFocusEmitter.event; private readonly _onWillScroll = this._register(new Emitter()); public readonly onWillScroll: Event = this._onWillScroll.event; + private readonly _onWillDispose = this._register(new Emitter()); + public readonly onWillDispose: Event = this._onWillDispose.event; set scrollTop(top: number) { if (this._list) { @@ -1672,6 +1674,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor dispose() { this._isDisposed = true; + this._onWillDispose.fire(); // dispose webview first this._webview?.dispose(); diff --git a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts index 77f8ab26eb2..7f69f420dd2 100644 --- a/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts +++ b/src/vs/workbench/contrib/notebook/test/testNotebookEditor.ts @@ -77,6 +77,7 @@ export class TestNotebookEditor implements INotebookEditor { onDidChangeAvailableKernels: Event = new Emitter().event; onDidChangeActiveCell: Event = new Emitter().event; onDidScroll = new Emitter().event; + onWillDispose = new Emitter().event; uri?: URI | undefined; textModel?: NotebookTextModel | undefined;