Merge pull request #1080 from danielyxie/dev

Fixed Script Editor not loading the same file after manually clicking it
This commit is contained in:
hydroflame 2021-08-22 01:31:00 -04:00 committed by GitHub
commit 8289c9fc75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

File diff suppressed because one or more lines are too long

@ -57,6 +57,7 @@ import {
loadAllRunningScripts, loadAllRunningScripts,
updateOnlineScriptTimes, updateOnlineScriptTimes,
} from "./NetscriptWorker"; } from "./NetscriptWorker";
import { GetServerByHostname } from "./Server/ServerHelpers";
import { Player } from "./Player"; import { Player } from "./Player";
import { prestigeAugmentation } from "./Prestige"; import { prestigeAugmentation } from "./Prestige";
import { import {
@ -226,6 +227,8 @@ const Engine = {
}, },
indexedDb: undefined, indexedDb: undefined,
lastFilename: '',
lastFilenameServer: '',
// Time variables (milliseconds unix epoch time) // Time variables (milliseconds unix epoch time)
_lastUpdate: new Date().getTime(), _lastUpdate: new Date().getTime(),
@ -251,9 +254,17 @@ const Engine = {
Engine.Display.scriptEditorContent.style.display = "block"; Engine.Display.scriptEditorContent.style.display = "block";
routing.navigateTo(Page.ScriptEditor); routing.navigateTo(Page.ScriptEditor);
if(filename !== "") {
this.lastFilename = filename;
this.lastFilenameServer = Player.getCurrentServer().hostname;
} else if(this.lastFilename !== '') {
const scripts = GetServerByHostname(this.lastFilenameServer).scripts.filter(x => x.filename === this.lastFilename);
if(scripts.length === 1) {
filename = this.lastFilename;
code = scripts[0].code;
}
}
const monaco = document.getElementById('monaco-editor');
//https://www.npmjs.com/package/@monaco-editor/react#development-playground
ReactDOM.render( ReactDOM.render(
<ScriptEditorRoot filename={filename} code={code} player={Player} engine={this} />, <ScriptEditorRoot filename={filename} code={code} player={Player} engine={this} />,
Engine.Display.scriptEditorContent, Engine.Display.scriptEditorContent,