diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index dd430c5d6..2093f0af0 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -32,8 +32,8 @@ import Typography from "@mui/material/Typography"; import Link from "@mui/material/Link"; import Box from "@mui/material/Box"; import SettingsIcon from "@mui/icons-material/Settings"; -import SyncIcon from '@mui/icons-material/Sync'; -import CloseIcon from '@mui/icons-material/Close'; +import SyncIcon from "@mui/icons-material/Sync"; +import CloseIcon from "@mui/icons-material/Close"; import Table from "@mui/material/Table"; import TableCell from "@mui/material/TableCell"; import TableRow from "@mui/material/TableRow"; @@ -133,13 +133,12 @@ export function Root(props: IProps): React.ReactElement { // Prevent Crash if script is open on deleted server openScripts = openScripts.filter((script) => { return GetServer(script.hostname) !== null; - }) - if (currentScript && (GetServer(currentScript.hostname) === null)) { + }); + if (currentScript && GetServer(currentScript.hostname) === null) { currentScript = openScripts[0]; if (currentScript === undefined) currentScript = null; } - const [dimensions, setDimensions] = useState({ height: window.innerHeight, width: window.innerWidth, @@ -208,7 +207,7 @@ export function Root(props: IProps): React.ReactElement { // Setup "go to next tab" and "go to previous tab". This is a little more involved // since these aren't Ex commands (they run in normal mode, not after typing `:`) - MonacoVim.VimMode.Vim.defineAction("nextTabs", function (_cm: any, args: {repeat?: number}, _vim: any) { + MonacoVim.VimMode.Vim.defineAction("nextTabs", function (_cm: any, args: { repeat?: number }) { const nTabs = args.repeat ?? 1; // Go to the next tab (to the right). Wraps around when at the rightmost tab const currIndex = currentTabIndex(); @@ -217,23 +216,23 @@ export function Root(props: IProps): React.ReactElement { onTabClick(nextIndex); } }); - MonacoVim.VimMode.Vim.defineAction("prevTabs", function (_cm: any, args: {repeat?: number}, _vim: any) { + MonacoVim.VimMode.Vim.defineAction("prevTabs", function (_cm: any, args: { repeat?: number }) { const nTabs = args.repeat ?? 1; // Go to the previous tab (to the left). Wraps around when at the leftmost tab const currIndex = currentTabIndex(); if (currIndex !== undefined) { - let nextIndex = (currIndex - nTabs); + let nextIndex = currIndex - nTabs; while (nextIndex < 0) { nextIndex += openScripts.length; } onTabClick(nextIndex); } }); - MonacoVim.VimMode.Vim.mapCommand("gt", "action", "nextTabs", {}, {context: "normal"}); - MonacoVim.VimMode.Vim.mapCommand("gT", "action", "prevTabs", {}, {context: "normal"}); + MonacoVim.VimMode.Vim.mapCommand("gt", "action", "nextTabs", {}, { context: "normal" }); + MonacoVim.VimMode.Vim.mapCommand("gT", "action", "prevTabs", {}, { context: "normal" }); editor.focus(); }); - } catch { } + } catch {} } else if (!options.vim) { // Whem vim mode is disabled vimEditor?.dispose(); @@ -342,13 +341,18 @@ export function Root(props: IProps): React.ReactElement { .loader(); // replaced the bare tokens with regexes surrounded by \b, e.g. \b{token}\b which matches a word-break on either side // this prevents the highlighter from highlighting pieces of variables that start with a reserved token name - l.language.tokenizer.root.unshift([new RegExp('\\bns\\b'), { token: "ns" }]); - for (const symbol of symbols) l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]); + l.language.tokenizer.root.unshift([new RegExp("\\bns\\b"), { token: "ns" }]); + for (const symbol of symbols) + l.language.tokenizer.root.unshift([new RegExp(`\\b${symbol}\\b`), { token: "netscriptfunction" }]); const otherKeywords = ["let", "const", "var", "function"]; const otherKeyvars = ["true", "false", "null", "undefined"]; - otherKeywords.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }])); - otherKeyvars.forEach((k) => l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }])); - l.language.tokenizer.root.unshift([new RegExp('\\bthis\\b'), { token: "this" }]); + otherKeywords.forEach((k) => + l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeywords" }]), + ); + otherKeyvars.forEach((k) => + l.language.tokenizer.root.unshift([new RegExp(`\\b${k}\\b`), { token: "otherkeyvars" }]), + ); + l.language.tokenizer.root.unshift([new RegExp("\\bthis\\b"), { token: "this" }]); })(); const source = (libSource + "").replace(/export /g, ""); @@ -474,7 +478,7 @@ export function Root(props: IProps): React.ReactElement { } try { infLoop(newCode); - } catch (err) { } + } catch (err) {} } function saveScript(scriptToSave: OpenScript): void { @@ -633,12 +637,12 @@ export function Root(props: IProps): React.ReactElement { function currentTabIndex(): number | undefined { if (currentScript !== null) { return openScripts.findIndex( - (script) => - currentScript !== null && - script.fileName === currentScript.fileName && - script.hostname === currentScript.hostname, - ); - } + (script) => + currentScript !== null && + script.fileName === currentScript.fileName && + script.hostname === currentScript.hostname, + ); + } return undefined; } @@ -737,15 +741,17 @@ export function Root(props: IProps): React.ReactElement { if (openScript.code !== serverScriptCode) { PromptEvent.emit({ - txt: "Do you want to overwrite the current editor content with the contents of " + - openScript.fileName + " on the server? This cannot be undone.", + txt: + "Do you want to overwrite the current editor content with the contents of " + + openScript.fileName + + " on the server? This cannot be undone.", resolve: (result: boolean) => { if (result) { // Save changes openScript.code = serverScriptCode; // Switch to target tab - onTabClick(index) + onTabClick(index); if (editorRef.current !== null && openScript !== null) { if (openScript.model === undefined || openScript.model.isDisposed()) { @@ -789,11 +795,11 @@ export function Root(props: IProps): React.ReactElement { // 44px bottom tool bar + 16px margin // + vim bar 34px const editorHeight = dimensions.height - (130 + (options.vim ? 34 : 0)); - const tabsMaxWidth = 1640 - const tabMargin = 5 - const tabMaxWidth = openScripts.length ? (tabsMaxWidth / openScripts.length) - tabMargin : 0 - const tabIconWidth = 25 - const tabTextWidth = tabMaxWidth - (tabIconWidth * 2) + const tabsMaxWidth = 1640; + const tabMargin = 5; + const tabMaxWidth = openScripts.length ? tabsMaxWidth / openScripts.length - tabMargin : 0; + const tabIconWidth = 25; + const tabTextWidth = tabMaxWidth - tabIconWidth * 2; return ( <>