feat: Hot keys: Escape to close settings, Up Arrow to get last input

This commit is contained in:
Mokou
2023-04-07 12:26:22 +08:00
parent fec055d8a8
commit 58b956f7cc
2 changed files with 21 additions and 0 deletions

View File

@@ -128,6 +128,19 @@ export function Settings(props: { closeSettings: () => void }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const keydownEvent = (e: KeyboardEvent) => {
if (e.key === "Escape") {
props.closeSettings();
}
};
document.addEventListener("keydown", keydownEvent);
return () => {
document.removeEventListener("keydown", keydownEvent);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<ErrorBoundary>
<div className={styles["window-header"]}>