Fix some key not working

This commit is contained in:
Olivier Gagnon 2022-03-20 23:11:26 -04:00
parent 81d1c02fdf
commit 05fe14a5ed
2 changed files with 52 additions and 54 deletions

@ -48,7 +48,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
const terminalInput = useRef<HTMLInputElement>(null);
const [value, setValue] = useState(command);
const [postUpdateValue, setPostUpdateValue] = useState<{postUpdate: () => void} | null>()
const [postUpdateValue, setPostUpdateValue] = useState<{ postUpdate: () => void } | null>();
const [possibilities, setPossibilities] = useState<string[]>([]);
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;

@ -1,55 +1,53 @@
import { IMap } from "../../types";
/**
* Keyboard key codes
*/
export const KEY: IMap<string> = {
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",
}