Merge pull request #2083 from 65-7a/txt-file-editor-patch

Script editor fixes for .txt files
This commit is contained in:
hydroflame 2021-12-21 10:49:08 -05:00 committed by GitHub
commit 7a9e8936ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -203,7 +203,7 @@ export function Root(props: IProps): React.ReactElement {
// Generates a new model for the script // Generates a new model for the script
function regenerateModel(script: OpenScript): void { function regenerateModel(script: OpenScript): void {
if (monacoRef.current !== null) { if (monacoRef.current !== null) {
script.model = monacoRef.current.editor.createModel(script.code, "javascript"); script.model = monacoRef.current.editor.createModel(script.code, script.fileName.endsWith(".txt") ? "plaintext" : "javascript");
} }
} }
@ -217,6 +217,10 @@ export function Root(props: IProps): React.ReactElement {
); );
async function updateRAM(newCode: string): Promise<void> { async function updateRAM(newCode: string): Promise<void> {
if (currentScript != null && currentScript.fileName.endsWith(".txt")) {
debouncedSetRAM("");
return;
}
setUpdatingRam(true); setUpdatingRam(true);
const codeCopy = newCode + ""; const codeCopy = newCode + "";
const ramUsage = await calculateRamUsage(codeCopy, props.player.getCurrentServer().scripts); const ramUsage = await calculateRamUsage(codeCopy, props.player.getCurrentServer().scripts);
@ -334,7 +338,7 @@ export function Root(props: IProps): React.ReactElement {
props.code, props.code,
props.hostname, props.hostname,
new monacoRef.current.Position(0, 0), new monacoRef.current.Position(0, 0),
monacoRef.current.editor.createModel(props.code, "javascript"), monacoRef.current.editor.createModel(props.code, props.filename.endsWith(".txt") ? "plaintext" : "javascript"),
); );
setOpenScripts((oldArray) => [...oldArray, newScript]); setOpenScripts((oldArray) => [...oldArray, newScript]);
setCurrentScript({ ...newScript }); setCurrentScript({ ...newScript });