From 60bab6a4286f4f12da8a2b6124d38043de3f6f2d Mon Sep 17 00:00:00 2001 From: "Daniel J. Geiger" <1852529+DanielJGeiger@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:27:47 -0600 Subject: [PATCH] feat: Widen `ActionName` and `ShortcutName` to include `custom.${string}` --- src/actions/shortcuts.ts | 12 +++++++++++- src/actions/types.ts | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/actions/shortcuts.ts b/src/actions/shortcuts.ts index 20ab9f7b44..528091f049 100644 --- a/src/actions/shortcuts.ts +++ b/src/actions/shortcuts.ts @@ -2,11 +2,12 @@ import { isDarwin } from "../constants"; import { t } from "../i18n"; import { SubtypeOf } from "../utility-types"; import { getShortcutKey } from "../utils"; -import { ActionName } from "./types"; +import { ActionName, CustomActionName } from "./types"; export type ShortcutName = | SubtypeOf< ActionName, + | CustomActionName | "toggleTheme" | "loadScene" | "clearCanvas" @@ -40,6 +41,15 @@ export type ShortcutName = | "saveScene" | "imageExport"; +export const registerCustomShortcuts = ( + shortcuts: Record, +) => { + for (const key in shortcuts) { + const shortcut = key as CustomActionName; + shortcutMap[shortcut] = shortcuts[shortcut]; + } +}; + const shortcutMap: Record = { toggleTheme: [getShortcutKey("Shift+Alt+D")], saveScene: [getShortcutKey("CtrlOrCmd+S")], diff --git a/src/actions/types.ts b/src/actions/types.ts index c74e19552c..1d6cf1660f 100644 --- a/src/actions/types.ts +++ b/src/actions/types.ts @@ -35,7 +35,11 @@ type ActionFn = ( export type UpdaterFn = (res: ActionResult) => void; export type ActionFilterFn = (action: Action) => void; +export const makeCustomActionName = (name: string) => + `custom.${name}` as CustomActionName; +export type CustomActionName = `custom.${string}`; export type ActionName = + | CustomActionName | "copy" | "cut" | "paste"