Explicitly dispose Monaco editor instance when cell is deleted (#232)

This commit is contained in:
Jonatan Kłosko 2021-04-21 17:38:48 +02:00 committed by GitHub
parent faeedcefc5
commit c498cfb211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View file

@ -83,6 +83,10 @@ const Cell = {
destroyed() { destroyed() {
globalPubSub.unsubscribe("session", this.handleSessionEvent); globalPubSub.unsubscribe("session", this.handleSessionEvent);
if (this.state.liveEditor) {
this.state.liveEditor.destroy();
}
}, },
updated() { updated() {

View file

@ -71,6 +71,20 @@ class LiveEditor {
.pushEditOperations([], [{ forceMoveMarkers: true, range, text }]); .pushEditOperations([], [{ forceMoveMarkers: true, range, text }]);
} }
/**
* Performs necessary cleanup actions.
*/
destroy() {
// Explicitly destroy the editor instance and its text model.
this.editor.dispose();
const model = this.editor.getModel();
if (model) {
model.dispose();
}
}
__mountEditor() { __mountEditor() {
this.editor = monaco.editor.create(this.container, { this.editor = monaco.editor.create(this.container, {
language: this.type, language: this.type,