BUGFIX: nano and vim open and save files on wrong servers in edge cases (#2795)

This commit is contained in:
catloversg
2026-05-22 07:42:52 +07:00
committed by GitHub
parent aaf249df11
commit cd94288da0
6 changed files with 21 additions and 20 deletions
+6 -1
View File
@@ -182,7 +182,12 @@ export function SidebarRoot(props: { page: Page }): React.ReactElement {
const clickPage = useCallback( const clickPage = useCallback(
(page: Page) => { (page: Page) => {
if (page == Page.ScriptEditor || page == Page.Documentation || page == Page.Options) { if (page == Page.ScriptEditor) {
Router.toPage(page, {
files: new Map(),
options: { vim: Settings.MonacoDefaultToVim, hostname: Player.currentServer },
});
} else if (page == Page.Documentation || page == Page.Options) {
Router.toPage(page, {}); Router.toPage(page, {});
} else if (isSimplePage(page)) { } else if (isSimplePage(page)) {
Router.toPage(page); Router.toPage(page);
+6 -9
View File
@@ -1,9 +1,9 @@
import { Terminal } from "../../../Terminal"; import { Terminal } from "../../../Terminal";
import { ScriptEditorRouteOptions, Page } from "../../../ui/Router"; import { Page } from "../../../ui/Router";
import { Router } from "../../../ui/GameRoot"; import { Router } from "../../../ui/GameRoot";
import { BaseServer } from "../../../Server/BaseServer"; import type { BaseServer } from "../../../Server/BaseServer";
import { type ScriptFilePath, hasScriptExtension, isLegacyScript } from "../../../Paths/ScriptFilePath"; import { type ScriptFilePath, hasScriptExtension, isLegacyScript } from "../../../Paths/ScriptFilePath";
import { TextFilePath, hasTextExtension } from "../../../Paths/TextFilePath"; import { type TextFilePath, hasTextExtension } from "../../../Paths/TextFilePath";
import { getGlobbedFileMap } from "../../../Paths/GlobbedFiles"; import { getGlobbedFileMap } from "../../../Paths/GlobbedFiles";
import { sendDeprecationNotice } from "./deprecation"; import { sendDeprecationNotice } from "./deprecation";
import { getFileType, getFileTypeFeature } from "../../../utils/ScriptTransformer"; import { getFileType, getFileTypeFeature } from "../../../utils/ScriptTransformer";
@@ -14,6 +14,7 @@ import { hasCacheExtension } from "../../../Paths/CacheFilePath";
interface EditorParameters { interface EditorParameters {
args: (string | number | boolean)[]; args: (string | number | boolean)[];
server: BaseServer; server: BaseServer;
vim: boolean;
} }
function getScriptTemplate(path: string): string { function getScriptTemplate(path: string): string {
@@ -33,11 +34,7 @@ export async function main(ns) {
} }
} }
export function commonEditor( export function commonEditor(command: string, { args, server, vim }: EditorParameters): void {
command: string,
{ args, server }: EditorParameters,
options?: ScriptEditorRouteOptions,
): void {
if (args.length < 1) return Terminal.error(`Incorrect usage of ${command} command. Usage: ${command} [scriptname]`); if (args.length < 1) return Terminal.error(`Incorrect usage of ${command} command. Usage: ${command} [scriptname]`);
const files = new Map<ScriptFilePath | TextFilePath, string>(); const files = new Map<ScriptFilePath | TextFilePath, string>();
let hasLegacyScript = false; let hasLegacyScript = false;
@@ -76,5 +73,5 @@ export function commonEditor(
if (hasLegacyScript) { if (hasLegacyScript) {
sendDeprecationNotice(); sendDeprecationNotice();
} }
Router.toPage(Page.ScriptEditor, { files, options }); Router.toPage(Page.ScriptEditor, { files, options: { vim, hostname: server.hostname } });
} }
+2 -2
View File
@@ -1,7 +1,7 @@
import { BaseServer } from "../../Server/BaseServer"; import type { BaseServer } from "../../Server/BaseServer";
import { commonEditor } from "./common/editor"; import { commonEditor } from "./common/editor";
export function nano(args: (string | number | boolean)[], server: BaseServer): void { export function nano(args: (string | number | boolean)[], server: BaseServer): void {
return commonEditor("nano", { args, server }, { vim: false }); return commonEditor("nano", { args, server, vim: false });
} }
+2 -2
View File
@@ -1,7 +1,7 @@
import { BaseServer } from "../../Server/BaseServer"; import type { BaseServer } from "../../Server/BaseServer";
import { commonEditor } from "./common/editor"; import { commonEditor } from "./common/editor";
export function vim(args: (string | number | boolean)[], server: BaseServer): void { export function vim(args: (string | number | boolean)[], server: BaseServer): void {
return commonEditor("vim", { args, server }, { vim: true }); return commonEditor("vim", { args, server, vim: true });
} }
+3 -4
View File
@@ -72,7 +72,6 @@ import { V2Modal } from "../utils/V2Modal";
import { useRerender } from "./React/hooks"; import { useRerender } from "./React/hooks";
import { HistoryProvider } from "./React/Documentation"; import { HistoryProvider } from "./React/Documentation";
import { GoRoot } from "../Go/ui/GoRoot"; import { GoRoot } from "../Go/ui/GoRoot";
import { Settings } from "../Settings/Settings";
import { isBitNodeFinished } from "../BitNode/BitNodeUtils"; import { isBitNodeFinished } from "../BitNode/BitNodeUtils";
import { UIEventEmitter, UIEventType } from "./UIEventEmitter"; import { UIEventEmitter, UIEventType } from "./UIEventEmitter";
import { exceptionAlert } from "../utils/helpers/exceptionAlert"; import { exceptionAlert } from "../utils/helpers/exceptionAlert";
@@ -351,9 +350,9 @@ export function GameRoot(): React.ReactElement {
case Page.ScriptEditor: { case Page.ScriptEditor: {
mainPage = ( mainPage = (
<ScriptEditorRoot <ScriptEditorRoot
files={pageWithContext.files ?? new Map()} files={pageWithContext.files}
hostname={pageWithContext.options?.hostname ?? Player.getCurrentServer().hostname} hostname={pageWithContext.options.hostname}
vim={pageWithContext.options === undefined ? Settings.MonacoDefaultToVim : pageWithContext.options.vim} vim={pageWithContext.options.vim}
/> />
); );
break; break;
+2 -2
View File
@@ -18,7 +18,7 @@ export type PageContext<T extends Page> = T extends ComplexPage.BitVerse
: T extends ComplexPage.FactionAugmentations : T extends ComplexPage.FactionAugmentations
? { faction: Faction } ? { faction: Faction }
: T extends ComplexPage.ScriptEditor : T extends ComplexPage.ScriptEditor
? { files?: Map<ScriptFilePath | TextFilePath, string>; options?: ScriptEditorRouteOptions } ? { files: Map<ScriptFilePath | TextFilePath, string>; options: ScriptEditorRouteOptions }
: T extends ComplexPage.Location : T extends ComplexPage.Location
? { location: Location } ? { location: Location }
: T extends ComplexPage.ImportSave : T extends ComplexPage.ImportSave
@@ -43,7 +43,7 @@ export type PageWithContext =
export interface ScriptEditorRouteOptions { export interface ScriptEditorRouteOptions {
vim: boolean; vim: boolean;
hostname?: string; hostname: string;
} }
/** The router keeps track of player navigation/routing within the game. */ /** The router keeps track of player navigation/routing within the game. */