mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 17:23:00 +02:00
MISC: Add key binding feature (#1830)
This commit is contained in:
@@ -38,6 +38,12 @@ import { RamCalculationErrorCode } from "../../Script/RamCalculationErrorCodes";
|
||||
import { hasScriptExtension, isLegacyScript, type ScriptFilePath } from "../../Paths/ScriptFilePath";
|
||||
import { exceptionAlert } from "../../utils/helpers/exceptionAlert";
|
||||
import type { BaseServer } from "../../Server/BaseServer";
|
||||
import {
|
||||
convertKeyboardEventToKeyCombination,
|
||||
CurrentKeyBindings,
|
||||
determineKeyBindingTypes,
|
||||
ScriptEditorAction,
|
||||
} from "../../utils/KeyBindingUtils";
|
||||
import { SpecialServers } from "../../Server/data/SpecialServers";
|
||||
import { SnackbarEvents } from "../../ui/React/Snackbar";
|
||||
import { ToastVariant } from "@enums";
|
||||
@@ -215,19 +221,19 @@ function Root(props: IProps): React.ReactElement {
|
||||
|
||||
useEffect(() => {
|
||||
function keydown(event: KeyboardEvent): void {
|
||||
if (Settings.DisableHotkeys) return;
|
||||
//Ctrl + b
|
||||
if (event.code == "KeyB" && (event.ctrlKey || event.metaKey)) {
|
||||
event.preventDefault();
|
||||
Router.toPage(Page.Terminal);
|
||||
if (Settings.DisableHotkeys) {
|
||||
return;
|
||||
}
|
||||
|
||||
// CTRL/CMD + S
|
||||
if (event.code == "KeyS" && (event.ctrlKey || event.metaKey)) {
|
||||
const keyBindingTypes = determineKeyBindingTypes(CurrentKeyBindings, convertKeyboardEventToKeyCombination(event));
|
||||
if (keyBindingTypes.has(ScriptEditorAction.Save)) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
save();
|
||||
}
|
||||
if (keyBindingTypes.has(ScriptEditorAction.GoToTerminal)) {
|
||||
event.preventDefault();
|
||||
Router.toPage(Page.Terminal);
|
||||
}
|
||||
}
|
||||
document.addEventListener("keydown", keydown);
|
||||
return () => document.removeEventListener("keydown", keydown);
|
||||
|
||||
@@ -22,6 +22,7 @@ import { Settings } from "../../Settings/Settings";
|
||||
import { OptionsModal, OptionsModalProps } from "./OptionsModal";
|
||||
import { useScriptEditorContext } from "./ScriptEditorContext";
|
||||
import { NsApiDocumentationLink } from "../../ui/React/NsApiDocumentationLink";
|
||||
import { CurrentKeyBindings, parseKeyCombinationsToString, ScriptEditorAction } from "../../utils/KeyBindingUtils";
|
||||
|
||||
type IStandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
|
||||
|
||||
@@ -67,10 +68,14 @@ export function Toolbar({ editor, onSave }: IProps) {
|
||||
<Button color={isUpdatingRAM ? "secondary" : "primary"} sx={{ mx: 1 }} onClick={openRAMInfo}>
|
||||
{ram}
|
||||
</Button>
|
||||
<Button onClick={onSave}>Save (Ctrl/Cmd + s)</Button>
|
||||
<Button sx={{ mx: 1 }} onClick={() => Router.toPage(Page.Terminal)}>
|
||||
Terminal (Ctrl/Cmd + b)
|
||||
</Button>
|
||||
<Tooltip title={parseKeyCombinationsToString(CurrentKeyBindings[ScriptEditorAction.Save])}>
|
||||
<Button onClick={onSave}>Save</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title={parseKeyCombinationsToString(CurrentKeyBindings[ScriptEditorAction.GoToTerminal])}>
|
||||
<Button sx={{ mx: 1 }} onClick={() => Router.toPage(Page.Terminal)}>
|
||||
Terminal
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Typography>
|
||||
<NsApiDocumentationLink />
|
||||
</Typography>
|
||||
|
||||
Reference in New Issue
Block a user