EDITOR: fix disposing models (#1026)

This commit is contained in:
Caldwell
2024-01-10 00:45:31 +01:00
committed by GitHub
parent 82511e5030
commit 6f8a59593a
4 changed files with 19 additions and 23 deletions
+4 -11
View File
@@ -22,7 +22,7 @@ import { PromptEvent } from "../../ui/React/PromptManager";
import { useRerender } from "../../ui/React/hooks";
import { dirty, getServerCode } from "./utils";
import { dirty, getServerCode, makeModel } from "./utils";
import { OpenScript } from "./OpenScript";
import { Tabs } from "./Tabs";
import { Toolbar } from "./Toolbar";
@@ -191,14 +191,7 @@ function Root(props: IProps): React.ReactElement {
code,
props.hostname,
new monaco.Position(0, 0),
monaco.editor.createModel(
code,
filename.endsWith(".txt") ? "plaintext" : "javascript",
monaco.Uri.from({
scheme: "file",
path: `${props.hostname}/${filename}`,
}),
),
makeModel(props.hostname, filename, code),
);
openScripts.push(newScript);
currentScript = newScript;
@@ -274,12 +267,12 @@ function Root(props: IProps): React.ReactElement {
// Save changes
closingScript.code = savedScriptCode;
saveScript(closingScript);
Router.toPage(Page.Terminal);
}
},
});
}
//unmounting the editor will dispose all, doesnt hurt to dispose on close aswell
closingScript.model.dispose();
openScripts.splice(index, 1);
if (openScripts.length === 0) {
currentScript = null;