mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-12 18:53:55 +01:00
EDITOR: changed editor tabs to have their own editor mode (#1372)
This commit is contained in:
parent
805ca06922
commit
bec6e82d7f
@ -42,6 +42,18 @@ export const MiscPage = (): React.ReactElement => {
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<OptionSwitch
|
||||||
|
checked={Settings.MonacoDefaultToVim}
|
||||||
|
onChange={(newValue) => (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.
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</GameOptionsPage>
|
</GameOptionsPage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -12,16 +12,25 @@ export class OpenScript {
|
|||||||
hostname: string;
|
hostname: string;
|
||||||
lastPosition: Position;
|
lastPosition: Position;
|
||||||
model: ITextModel;
|
model: ITextModel;
|
||||||
|
vimMode: boolean;
|
||||||
isTxt: boolean;
|
isTxt: boolean;
|
||||||
// TODO: Adding actual external update notifications for the OpenScript class
|
// TODO: Adding actual external update notifications for the OpenScript class
|
||||||
// hasExternalUpdate = false;
|
// 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.path = path;
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.lastPosition = lastPosition;
|
this.lastPosition = lastPosition;
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.vimMode = vimMode;
|
||||||
this.isTxt = hasTextExtension(path);
|
this.isTxt = hasTextExtension(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ export interface Options {
|
|||||||
fontSize: number;
|
fontSize: number;
|
||||||
fontLigatures: boolean;
|
fontLigatures: boolean;
|
||||||
wordWrap: WordWrapOptions;
|
wordWrap: WordWrapOptions;
|
||||||
vim: boolean;
|
|
||||||
cursorStyle: CursorStyle;
|
cursorStyle: CursorStyle;
|
||||||
cursorBlinking: CursorBlinking;
|
cursorBlinking: CursorBlinking;
|
||||||
}
|
}
|
||||||
|
@ -93,11 +93,6 @@ export function OptionsModal(props: OptionsModalProps): ReactElement {
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
|
||||||
<Typography marginRight={"auto"}>Enable vim mode: </Typography>
|
|
||||||
<Switch onChange={(e) => props.onOptionChange("vim", e.target.checked)} checked={props.options.vim} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style={{ display: "flex", alignItems: "center" }}>
|
<div style={{ display: "flex", alignItems: "center" }}>
|
||||||
<Typography marginRight={"auto"}>Font family: </Typography>
|
<Typography marginRight={"auto"}>Font family: </Typography>
|
||||||
<TextField
|
<TextField
|
||||||
|
@ -26,7 +26,7 @@ export interface ScriptEditorContextShape {
|
|||||||
|
|
||||||
const ScriptEditorContext = React.createContext({} as ScriptEditorContextShape);
|
const ScriptEditorContext = React.createContext({} as ScriptEditorContextShape);
|
||||||
|
|
||||||
export function ScriptEditorContextProvider({ children, vim }: { children: React.ReactNode; vim: boolean }) {
|
export function ScriptEditorContextProvider({ children }: { children: React.ReactNode }) {
|
||||||
const [ram, setRAM] = useState("RAM: ???");
|
const [ram, setRAM] = useState("RAM: ???");
|
||||||
const [ramEntries, setRamEntries] = useState<string[][]>([["???", ""]]);
|
const [ramEntries, setRamEntries] = useState<string[][]>([["???", ""]]);
|
||||||
|
|
||||||
@ -76,7 +76,6 @@ export function ScriptEditorContextProvider({ children, vim }: { children: React
|
|||||||
fontSize: Settings.MonacoFontSize,
|
fontSize: Settings.MonacoFontSize,
|
||||||
fontLigatures: Settings.MonacoFontLigatures,
|
fontLigatures: Settings.MonacoFontLigatures,
|
||||||
wordWrap: Settings.MonacoWordWrap,
|
wordWrap: Settings.MonacoWordWrap,
|
||||||
vim: vim || Settings.MonacoVim,
|
|
||||||
cursorStyle: Settings.MonacoCursorStyle,
|
cursorStyle: Settings.MonacoCursorStyle,
|
||||||
cursorBlinking: Settings.MonacoCursorBlinking,
|
cursorBlinking: Settings.MonacoCursorBlinking,
|
||||||
});
|
});
|
||||||
@ -93,7 +92,6 @@ export function ScriptEditorContextProvider({ children, vim }: { children: React
|
|||||||
Settings.MonacoCursorStyle = options.cursorStyle;
|
Settings.MonacoCursorStyle = options.cursorStyle;
|
||||||
Settings.MonacoCursorBlinking = options.cursorBlinking;
|
Settings.MonacoCursorBlinking = options.cursorBlinking;
|
||||||
Settings.MonacoWordWrap = options.wordWrap;
|
Settings.MonacoWordWrap = options.wordWrap;
|
||||||
Settings.MonacoVim = options.vim;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -44,7 +44,7 @@ function Root(props: IProps): React.ReactElement {
|
|||||||
const rerender = useRerender();
|
const rerender = useRerender();
|
||||||
const editorRef = useRef<IStandaloneCodeEditor | null>(null);
|
const editorRef = useRef<IStandaloneCodeEditor | null>(null);
|
||||||
|
|
||||||
const { options, updateRAM, startUpdatingRAM, finishUpdatingRAM } = useScriptEditorContext();
|
const { updateRAM, startUpdatingRAM, finishUpdatingRAM } = useScriptEditorContext();
|
||||||
|
|
||||||
let decorations: monaco.editor.IEditorDecorationsCollection | undefined;
|
let decorations: monaco.editor.IEditorDecorationsCollection | undefined;
|
||||||
|
|
||||||
@ -194,6 +194,7 @@ function Root(props: IProps): React.ReactElement {
|
|||||||
props.hostname,
|
props.hostname,
|
||||||
new monaco.Position(0, 0),
|
new monaco.Position(0, 0),
|
||||||
makeModel(props.hostname, filename, code),
|
makeModel(props.hostname, filename, code),
|
||||||
|
props.vim,
|
||||||
);
|
);
|
||||||
openScripts.push(newScript);
|
openScripts.push(newScript);
|
||||||
currentScript = newScript;
|
currentScript = newScript;
|
||||||
@ -375,7 +376,7 @@ function Root(props: IProps): React.ReactElement {
|
|||||||
|
|
||||||
const { statusBarRef } = useVimEditor({
|
const { statusBarRef } = useVimEditor({
|
||||||
editor: editorRef.current,
|
editor: editorRef.current,
|
||||||
vim: options.vim,
|
vim: currentScript !== null ? currentScript.vimMode : props.vim,
|
||||||
onSave: save,
|
onSave: save,
|
||||||
onOpenNextTab,
|
onOpenNextTab,
|
||||||
onOpenPreviousTab,
|
onOpenPreviousTab,
|
||||||
@ -423,7 +424,7 @@ function Root(props: IProps): React.ReactElement {
|
|||||||
// Called every time script editor is opened
|
// Called every time script editor is opened
|
||||||
export function ScriptEditorRoot(props: IProps) {
|
export function ScriptEditorRoot(props: IProps) {
|
||||||
return (
|
return (
|
||||||
<ScriptEditorContextProvider vim={props.vim}>
|
<ScriptEditorContextProvider>
|
||||||
<Root {...props} />
|
<Root {...props} />
|
||||||
</ScriptEditorContextProvider>
|
</ScriptEditorContextProvider>
|
||||||
);
|
);
|
||||||
|
@ -101,7 +101,7 @@ export const Settings = {
|
|||||||
/** Whether to use font ligatures */
|
/** Whether to use font ligatures */
|
||||||
MonacoFontLigatures: false,
|
MonacoFontLigatures: false,
|
||||||
/** Whether to use Vim mod by default in the script editor */
|
/** Whether to use Vim mod by default in the script editor */
|
||||||
MonacoVim: false,
|
MonacoDefaultToVim: false,
|
||||||
/** Word wrap setting for Script Editor. */
|
/** Word wrap setting for Script Editor. */
|
||||||
MonacoWordWrap: "off" as WordWrapOptions,
|
MonacoWordWrap: "off" as WordWrapOptions,
|
||||||
/** Control the cursor style*/
|
/** Control the cursor style*/
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
root,
|
root,
|
||||||
} from "../../Paths/Directory";
|
} from "../../Paths/Directory";
|
||||||
import { isMember } from "../../utils/EnumHelper";
|
import { isMember } from "../../utils/EnumHelper";
|
||||||
|
import { Settings } from "../../Settings/Settings";
|
||||||
|
|
||||||
export function ls(args: (string | number | boolean)[], server: BaseServer): void {
|
export function ls(args: (string | number | boolean)[], server: BaseServer): void {
|
||||||
interface LSFlags {
|
interface LSFlags {
|
||||||
@ -138,7 +139,7 @@ export function ls(args: (string | number | boolean)[], server: BaseServer): voi
|
|||||||
content = server.scripts.get(fullPath)?.content ?? "";
|
content = server.scripts.get(fullPath)?.content ?? "";
|
||||||
}
|
}
|
||||||
const files = new Map<ContentFilePath, string>();
|
const files = new Map<ContentFilePath, string>();
|
||||||
const options = { hostname: server.hostname };
|
const options = { hostname: server.hostname, vim: Settings.MonacoDefaultToVim };
|
||||||
files.set(fullPath, content);
|
files.set(fullPath, content);
|
||||||
Router.toPage(Page.ScriptEditor, { files, options });
|
Router.toPage(Page.ScriptEditor, { files, options });
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ import { 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 });
|
return commonEditor("nano", { args, server }, { vim: false });
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ import { MathJaxContext } from "better-react-mathjax";
|
|||||||
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";
|
||||||
|
|
||||||
const htmlLocation = location;
|
const htmlLocation = location;
|
||||||
@ -252,7 +253,7 @@ export function GameRoot(): React.ReactElement {
|
|||||||
<ScriptEditorRoot
|
<ScriptEditorRoot
|
||||||
files={pageWithContext.files ?? new Map()}
|
files={pageWithContext.files ?? new Map()}
|
||||||
hostname={pageWithContext.options?.hostname ?? Player.getCurrentServer().hostname}
|
hostname={pageWithContext.options?.hostname ?? Player.getCurrentServer().hostname}
|
||||||
vim={!!pageWithContext.options?.vim}
|
vim={pageWithContext.options === undefined ? Settings.MonacoDefaultToVim : pageWithContext.options.vim}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -89,7 +89,7 @@ export type PageWithContext =
|
|||||||
| { page: SimplePage };
|
| { page: SimplePage };
|
||||||
|
|
||||||
export interface ScriptEditorRouteOptions {
|
export interface ScriptEditorRouteOptions {
|
||||||
vim?: boolean;
|
vim: boolean;
|
||||||
hostname?: string;
|
hostname?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user