mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 01:53:48 +01:00
const openScripts
This commit is contained in:
parent
8cbb8aac2e
commit
57fa1b743a
@ -102,7 +102,7 @@ class OpenScript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let openScripts: OpenScript[] = [];
|
const openScripts: OpenScript[] = [];
|
||||||
let currentScript: OpenScript | null = null;
|
let currentScript: OpenScript | null = null;
|
||||||
|
|
||||||
// Called every time script editor is opened
|
// Called every time script editor is opened
|
||||||
@ -136,9 +136,9 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
const [ramInfoOpen, setRamInfoOpen] = useState(false);
|
const [ramInfoOpen, setRamInfoOpen] = useState(false);
|
||||||
|
|
||||||
// Prevent Crash if script is open on deleted server
|
// Prevent Crash if script is open on deleted server
|
||||||
openScripts = openScripts.filter((script) => {
|
for (let i=openScripts.length-1;i>=0;i--){
|
||||||
return GetServer(script.hostname) !== null;
|
GetServer(openScripts[i].hostname) === null && openScripts.splice(i,1);
|
||||||
});
|
}
|
||||||
if (currentScript && GetServer(currentScript.hostname) === null) {
|
if (currentScript && GetServer(currentScript.hostname) === null) {
|
||||||
currentScript = openScripts[0];
|
currentScript = openScripts[0];
|
||||||
if (currentScript === undefined) currentScript = null;
|
if (currentScript === undefined) currentScript = null;
|
||||||
@ -665,29 +665,29 @@ export function Root(props: IProps): React.ReactElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (openScripts.length > 1) {
|
|
||||||
openScripts.splice(index, 1);
|
openScripts.splice(index, 1);
|
||||||
const indexOffset = openScripts.length === index ? -1 : 0;
|
if (openScripts.length === 0) {
|
||||||
|
currentScript = null;
|
||||||
|
props.router.toTerminal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Change current script if we closed it
|
// Change current script if we closed it
|
||||||
currentScript = wasCurrentScript ? openScripts[index + indexOffset] : (currentScript as OpenScript);
|
if(wasCurrentScript){
|
||||||
|
//Keep the same index unless we were on the last script
|
||||||
|
const indexOffset = openScripts.length === index ? -1 : 0;
|
||||||
|
currentScript = openScripts[index + indexOffset];
|
||||||
if (editorRef.current !== null) {
|
if (editorRef.current !== null) {
|
||||||
if (currentScript.model.isDisposed() || !currentScript.model) {
|
if (currentScript.model.isDisposed() || !currentScript.model) {
|
||||||
regenerateModel(currentScript);
|
regenerateModel(currentScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
editorRef.current.setModel(currentScript.model);
|
editorRef.current.setModel(currentScript.model);
|
||||||
editorRef.current.setPosition(currentScript.lastPosition);
|
editorRef.current.setPosition(currentScript.lastPosition);
|
||||||
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
editorRef.current.revealLineInCenter(currentScript.lastPosition.lineNumber);
|
||||||
editorRef.current.focus();
|
editorRef.current.focus();
|
||||||
}
|
}
|
||||||
rerender();
|
|
||||||
} else {
|
|
||||||
// No more scripts are open
|
|
||||||
openScripts = [];
|
|
||||||
currentScript = null;
|
|
||||||
props.router.toTerminal();
|
|
||||||
}
|
}
|
||||||
|
rerender();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTabUpdate(index: number): void {
|
function onTabUpdate(index: number): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user