MISC: Add key binding feature (#1830)

This commit is contained in:
catloversg
2025-02-28 13:59:12 +07:00
committed by GitHub
parent 3ba89eb388
commit 8ed83f3d37
44 changed files with 1201 additions and 305 deletions
+14 -8
View File
@@ -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);