From 159cc9bf30970e576bcb4b57631b2ae81cc61c6e Mon Sep 17 00:00:00 2001 From: Ian Huff Date: Fri, 12 Feb 2021 14:53:18 -0800 Subject: [PATCH] Only clean up editors on close not on Panel dispose (#4787) --- news/2 Fixes/4786.md | 1 + .../datascience/notebook/notebookEditor.ts | 2 +- .../notebook/notebookEditorProvider.ts | 18 ------------------ 3 files changed, 2 insertions(+), 19 deletions(-) create mode 100644 news/2 Fixes/4786.md diff --git a/news/2 Fixes/4786.md b/news/2 Fixes/4786.md new file mode 100644 index 00000000000..13edddf96cd --- /dev/null +++ b/news/2 Fixes/4786.md @@ -0,0 +1 @@ +Only clean up a notebook editor when it's closed, not when the panel is disposed. \ No newline at end of file diff --git a/src/client/datascience/notebook/notebookEditor.ts b/src/client/datascience/notebook/notebookEditor.ts index 865910e61ea..6cd7e2f402c 100644 --- a/src/client/datascience/notebook/notebookEditor.ts +++ b/src/client/datascience/notebook/notebookEditor.ts @@ -95,7 +95,7 @@ export class NotebookEditor implements INotebookEditor { } }) ); - disposables.push(model.onDidDispose(this._closed.fire.bind(this._closed, this))); + disposables.push(model.onDidDispose(this.dispose.bind(this))); } @captureTelemetry(Telemetry.SyncAllCells) public async syncAllCells(): Promise { diff --git a/src/client/datascience/notebook/notebookEditorProvider.ts b/src/client/datascience/notebook/notebookEditorProvider.ts index 395de049c9d..0abf98ab76f 100644 --- a/src/client/datascience/notebook/notebookEditorProvider.ts +++ b/src/client/datascience/notebook/notebookEditorProvider.ts @@ -184,7 +184,6 @@ export class NotebookEditorProvider implements INotebookEditorProvider { return; } this.trackedVSCodeNotebookEditors.add(editor); - this.disposables.push(editor.onDidDispose(() => this.onDidDisposeVSCodeNotebookEditor(editor))); } private async onDidCloseNotebookDocument(document: NotebookDocument) { this.disposeResourceRelatedToNotebookEditor(document.uri); @@ -207,21 +206,4 @@ export class NotebookEditorProvider implements INotebookEditorProvider { this.notebookEditorsByUri.delete(uri.toString()); this.notebooksWaitingToBeOpenedByUri.delete(uri.toString()); } - /** - * We know a notebook editor has been closed. - * We need to close/dispose all of our resources related to this notebook document. - * However we also need to check if there are other notebooks opened, that are associated with this same notebook. - * I.e. we may have closed a duplicate editor. - */ - private async onDidDisposeVSCodeNotebookEditor(closedEditor: VSCodeNotebookEditor) { - const uri = closedEditor.document.uri; - if ( - this.vscodeNotebook.notebookEditors.some( - (item) => item !== closedEditor && item.document.uri.toString() === uri.toString() - ) - ) { - return; - } - this.disposeResourceRelatedToNotebookEditor(closedEditor.document.uri); - } }