aboutsummaryrefslogtreecommitdiff
path: root/source/library/state/keyboard.ts
diff options
context:
space:
mode:
Diffstat (limited to 'source/library/state/keyboard.ts')
-rw-r--r--source/library/state/keyboard.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/library/state/keyboard.ts b/source/library/state/keyboard.ts
new file mode 100644
index 0000000..5f07b2c
--- /dev/null
+++ b/source/library/state/keyboard.ts
@@ -0,0 +1,50 @@
+
+
+
+
+/*** EXPORT ------------------------------------------- ***/
+
+export type ShortcutAction =
+ | { type: "closeTab" }
+ | { type: "format" }
+ | { type: "newTab" }
+ | { type: "nextTab" }
+ | { type: "prevTab" }
+ | { type: "run" };
+
+export function matchShortcut(event: KeyboardEvent): ShortcutAction | null {
+ const meta = event.metaKey || event.ctrlKey;
+
+ if (!meta)
+ return null;
+
+ if (event.key === "Enter") {
+ if (event.shiftKey)
+ return { type: "newTab" };
+
+ if (!event.altKey)
+ return { type: "run" };
+
+ return null;
+ }
+
+ if (event.shiftKey && !event.altKey) {
+ const key = event.key.toLowerCase();
+
+ if (key === "w")
+ return { type: "closeTab" };
+
+ if (key === "f")
+ return { type: "format" };
+ }
+
+ if (event.altKey && !event.shiftKey) {
+ if (event.key === "ArrowRight")
+ return { type: "nextTab" };
+
+ if (event.key === "ArrowLeft")
+ return { type: "prevTab" };
+ }
+
+ return null;
+}