From 05fe14a5eddb815324f2dea8d1c9c0e71e42bf02 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 20 Mar 2022 23:11:26 -0400 Subject: [PATCH] Fix some key not working --- src/Terminal/ui/TerminalInput.tsx | 14 ++--- src/utils/helpers/keyCodes.ts | 92 +++++++++++++++---------------- 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index a45d7ec6b..f84623535 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -48,7 +48,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React const terminalInput = useRef(null); const [value, setValue] = useState(command); - const [postUpdateValue, setPostUpdateValue] = useState<{postUpdate: () => void} | null>() + const [postUpdateValue, setPostUpdateValue] = useState<{ postUpdate: () => void } | null>(); const [possibilities, setPossibilities] = useState([]); const classes = useStyles(); @@ -65,14 +65,14 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React postUpdateValue.postUpdate(); setPostUpdateValue(null); } - }, [postUpdateValue]) + }, [postUpdateValue]); function saveValue(newValue: string, postUpdate?: () => void): void { command = newValue; setValue(newValue); if (postUpdate) { - setPostUpdateValue({postUpdate}); + setPostUpdateValue({ postUpdate }); } } @@ -102,7 +102,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React // Move cursor to correct location // foo bar |baz bum --> foo |baz bum const ref = terminalInput.current; - ref?.setSelectionRange(delStart+1, delStart+1); + ref?.setSelectionRange(delStart + 1, delStart + 1); }); return; } @@ -115,7 +115,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React // Move cursor to correct location // foo bar |baz bum --> foo bar |bum const ref = terminalInput.current; - ref?.setSelectionRange(start, start) + ref?.setSelectionRange(start, start); }); return; } @@ -180,7 +180,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React useEffect(() => { function keyDown(this: Document, event: KeyboardEvent): void { if (terminal.contractOpen) return; - if (terminal.action !== null && event.key === KEY.c && event.ctrlKey) { + if (terminal.action !== null && event.key === KEY.C && event.ctrlKey) { terminal.finishAction(router, player, true); return; } @@ -205,7 +205,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } // Autocomplete - if (event.key === KEY.Tab && value !== "") { + if (event.key === KEY.TAB && value !== "") { event.preventDefault(); let copy = value; diff --git a/src/utils/helpers/keyCodes.ts b/src/utils/helpers/keyCodes.ts index 60e6c0dc1..a03290a26 100644 --- a/src/utils/helpers/keyCodes.ts +++ b/src/utils/helpers/keyCodes.ts @@ -1,55 +1,53 @@ -import { IMap } from "../../types"; - /** * Keyboard key codes */ -export const KEY: IMap = { +export enum KEY { //SHIFT: 16, // Check by `&& event.shiftKey` //CTRL: 17, // Check by `&& event.ctrlKey` //ALT: 18, // Check by `&& event.altKey` - ENTER: "Enter", - ESC: "Escape", - TAB: "Tab", - UPARROW: "ArrowUp", - DOWNARROW: "ArrowDown", - LEFTARROW: "ArrowLeft", - RIGHTARROW: "ArrowRight", + ENTER = "Enter", + ESC = "Escape", + TAB = "Tab", + UPARROW = "ArrowUp", + DOWNARROW = "ArrowDown", + LEFTARROW = "ArrowLeft", + RIGHTARROW = "ArrowRight", - "0": "0", - "1": "1", - "2": "2", - "3": "3", - "4": "4", - "5": "5", - "6": "6", - "7": "7", - "8": "8", - "9": "9", + k0 = "0", + k1 = "1", + k2 = "2", + k3 = "3", + k4 = "4", + k5 = "5", + k6 = "6", + k7 = "7", + k8 = "8", + k9 = "9", - A: "a", - B: "b", - C: "c", - D: "d", - E: "e", - F: "f", - G: "g", - H: "h", - I: "i", - J: "j", - K: "k", - L: "l", - M: "m", - N: "n", - O: "o", - P: "p", - Q: "q", - R: "r", - S: "s", - T: "t", - U: "u", - V: "v", - W: "w", - X: "x", - Y: "y", - Z: "z", -}; + A = "a", + B = "b", + C = "c", + D = "d", + E = "e", + F = "f", + G = "g", + H = "h", + I = "i", + J = "j", + K = "k", + L = "l", + M = "m", + N = "n", + O = "o", + P = "p", + Q = "q", + R = "r", + S = "s", + T = "t", + U = "u", + V = "v", + W = "w", + X = "x", + Y = "y", + Z = "z", +}