Skip to content

Commit

Permalink
Only clean up editors on close not on Panel dispose (#4787)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMatthewHuff authored Feb 12, 2021
1 parent 35162ca commit 159cc9b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
1 change: 1 addition & 0 deletions news/2 Fixes/4786.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only clean up a notebook editor when it's closed, not when the panel is disposed.
2 changes: 1 addition & 1 deletion src/client/datascience/notebook/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
18 changes: 0 additions & 18 deletions src/client/datascience/notebook/notebookEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit 159cc9b

Please sign in to comment.