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
+11 -2
View File
@@ -1,5 +1,5 @@
import { GetServer } from "../../Server/AllServers";
import { editor, Uri } from "monaco-editor";
import { OpenScript } from "./OpenScript";
function getServerCode(scripts: OpenScript[], index: number): string | null {
@@ -21,5 +21,14 @@ function reorder(list: unknown[], startIndex: number, endIndex: number): void {
const [removed] = list.splice(startIndex, 1);
list.splice(endIndex, 0, removed);
}
function makeModel(hostname: string, filename: string, code: string) {
const uri = Uri.from({
scheme: "file",
path: `${hostname}/${filename}`,
});
const language = filename.endsWith(".txt") ? "plaintext" : "javascript";
//if somehow a model already exist return it
return editor.getModel(uri) ?? editor.createModel(code, language, uri);
}
export { getServerCode, dirty, reorder };
export { getServerCode, dirty, reorder, makeModel };