diff --git a/src/GameOptions/ui/MiscPage.tsx b/src/GameOptions/ui/MiscPage.tsx index 9421b988e..703d8b651 100644 --- a/src/GameOptions/ui/MiscPage.tsx +++ b/src/GameOptions/ui/MiscPage.tsx @@ -42,6 +42,18 @@ export const MiscPage = (): React.ReactElement => { } /> + (Settings.MonacoDefaultToVim = newValue)} + text="Enable Vim as default editor" + tooltip={ + <> + This setting is only used when opening a file through ways that do not determine the editor mode. Using + 'nano' or 'vim' will set the editor mode for the specified files, while 'ls' will open the file using the + the value from this setting. + + } + /> ); }; diff --git a/src/ScriptEditor/ui/OpenScript.ts b/src/ScriptEditor/ui/OpenScript.ts index df4164ff1..4c6667f9d 100644 --- a/src/ScriptEditor/ui/OpenScript.ts +++ b/src/ScriptEditor/ui/OpenScript.ts @@ -12,16 +12,25 @@ export class OpenScript { hostname: string; lastPosition: Position; model: ITextModel; + vimMode: boolean; isTxt: boolean; // TODO: Adding actual external update notifications for the OpenScript class // hasExternalUpdate = false; - constructor(path: ContentFilePath, code: string, hostname: string, lastPosition: Position, model: ITextModel) { + constructor( + path: ContentFilePath, + code: string, + hostname: string, + lastPosition: Position, + model: ITextModel, + vimMode: boolean, + ) { this.path = path; this.code = code; this.hostname = hostname; this.lastPosition = lastPosition; this.model = model; + this.vimMode = vimMode; this.isTxt = hasTextExtension(path); } diff --git a/src/ScriptEditor/ui/Options.ts b/src/ScriptEditor/ui/Options.ts index 9ea9dbc2c..d7e43b83d 100644 --- a/src/ScriptEditor/ui/Options.ts +++ b/src/ScriptEditor/ui/Options.ts @@ -14,7 +14,6 @@ export interface Options { fontSize: number; fontLigatures: boolean; wordWrap: WordWrapOptions; - vim: boolean; cursorStyle: CursorStyle; cursorBlinking: CursorBlinking; } diff --git a/src/ScriptEditor/ui/OptionsModal.tsx b/src/ScriptEditor/ui/OptionsModal.tsx index 93a92d473..27db47897 100644 --- a/src/ScriptEditor/ui/OptionsModal.tsx +++ b/src/ScriptEditor/ui/OptionsModal.tsx @@ -93,11 +93,6 @@ export function OptionsModal(props: OptionsModalProps): ReactElement { -
- Enable vim mode: - props.onOptionChange("vim", e.target.checked)} checked={props.options.vim} /> -
-
Font family: ([["???", ""]]); @@ -76,7 +76,6 @@ export function ScriptEditorContextProvider({ children, vim }: { children: React fontSize: Settings.MonacoFontSize, fontLigatures: Settings.MonacoFontLigatures, wordWrap: Settings.MonacoWordWrap, - vim: vim || Settings.MonacoVim, cursorStyle: Settings.MonacoCursorStyle, cursorBlinking: Settings.MonacoCursorBlinking, }); @@ -93,7 +92,6 @@ export function ScriptEditorContextProvider({ children, vim }: { children: React Settings.MonacoCursorStyle = options.cursorStyle; Settings.MonacoCursorBlinking = options.cursorBlinking; Settings.MonacoWordWrap = options.wordWrap; - Settings.MonacoVim = options.vim; } return ( diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 1bb31320c..0ec659157 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -44,7 +44,7 @@ function Root(props: IProps): React.ReactElement { const rerender = useRerender(); const editorRef = useRef(null); - const { options, updateRAM, startUpdatingRAM, finishUpdatingRAM } = useScriptEditorContext(); + const { updateRAM, startUpdatingRAM, finishUpdatingRAM } = useScriptEditorContext(); let decorations: monaco.editor.IEditorDecorationsCollection | undefined; @@ -194,6 +194,7 @@ function Root(props: IProps): React.ReactElement { props.hostname, new monaco.Position(0, 0), makeModel(props.hostname, filename, code), + props.vim, ); openScripts.push(newScript); currentScript = newScript; @@ -375,7 +376,7 @@ function Root(props: IProps): React.ReactElement { const { statusBarRef } = useVimEditor({ editor: editorRef.current, - vim: options.vim, + vim: currentScript !== null ? currentScript.vimMode : props.vim, onSave: save, onOpenNextTab, onOpenPreviousTab, @@ -423,7 +424,7 @@ function Root(props: IProps): React.ReactElement { // Called every time script editor is opened export function ScriptEditorRoot(props: IProps) { return ( - + ); diff --git a/src/Settings/Settings.ts b/src/Settings/Settings.ts index 95e294bbf..97cb68991 100644 --- a/src/Settings/Settings.ts +++ b/src/Settings/Settings.ts @@ -101,7 +101,7 @@ export const Settings = { /** Whether to use font ligatures */ MonacoFontLigatures: false, /** Whether to use Vim mod by default in the script editor */ - MonacoVim: false, + MonacoDefaultToVim: false, /** Word wrap setting for Script Editor. */ MonacoWordWrap: "off" as WordWrapOptions, /** Control the cursor style*/ diff --git a/src/Terminal/commands/ls.tsx b/src/Terminal/commands/ls.tsx index ef1858642..7b2d9638f 100644 --- a/src/Terminal/commands/ls.tsx +++ b/src/Terminal/commands/ls.tsx @@ -24,6 +24,7 @@ import { root, } from "../../Paths/Directory"; import { isMember } from "../../utils/EnumHelper"; +import { Settings } from "../../Settings/Settings"; export function ls(args: (string | number | boolean)[], server: BaseServer): void { interface LSFlags { @@ -138,7 +139,7 @@ export function ls(args: (string | number | boolean)[], server: BaseServer): voi content = server.scripts.get(fullPath)?.content ?? ""; } const files = new Map(); - const options = { hostname: server.hostname }; + const options = { hostname: server.hostname, vim: Settings.MonacoDefaultToVim }; files.set(fullPath, content); Router.toPage(Page.ScriptEditor, { files, options }); } diff --git a/src/Terminal/commands/nano.ts b/src/Terminal/commands/nano.ts index 9e5718482..88d36bbf1 100644 --- a/src/Terminal/commands/nano.ts +++ b/src/Terminal/commands/nano.ts @@ -3,5 +3,5 @@ import { BaseServer } from "../../Server/BaseServer"; import { commonEditor } from "./common/editor"; export function nano(args: (string | number | boolean)[], server: BaseServer): void { - return commonEditor("nano", { args, server }); + return commonEditor("nano", { args, server }, { vim: false }); } diff --git a/src/ui/GameRoot.tsx b/src/ui/GameRoot.tsx index 5d1c95811..5b14816b5 100644 --- a/src/ui/GameRoot.tsx +++ b/src/ui/GameRoot.tsx @@ -72,6 +72,7 @@ import { MathJaxContext } from "better-react-mathjax"; import { useRerender } from "./React/hooks"; import { HistoryProvider } from "./React/Documentation"; import { GoRoot } from "../Go/ui/GoRoot"; +import { Settings } from "../Settings/Settings"; import { isBitNodeFinished } from "../BitNode/BitNodeUtils"; const htmlLocation = location; @@ -252,7 +253,7 @@ export function GameRoot(): React.ReactElement { ); break; diff --git a/src/ui/Router.ts b/src/ui/Router.ts index b40e4bf5e..2c0e2744b 100644 --- a/src/ui/Router.ts +++ b/src/ui/Router.ts @@ -89,7 +89,7 @@ export type PageWithContext = | { page: SimplePage }; export interface ScriptEditorRouteOptions { - vim?: boolean; + vim: boolean; hostname?: string; }