({
shortcut,
action,
disabled = false,
enabledOnInputElements,
}: useShortcutKeysProps)
| 24 | }; |
| 25 | |
| 26 | export function useShortcutKeys({ |
| 27 | shortcut, |
| 28 | action, |
| 29 | disabled = false, |
| 30 | enabledOnInputElements, |
| 31 | }: useShortcutKeysProps) { |
| 32 | const { platform } = useOperatingSystem(); |
| 33 | const isMac = platform === "mac"; |
| 34 | const relevantShortcut = |
| 35 | shortcut && "mac" in shortcut ? (isMac ? shortcut.mac : shortcut.windows) : shortcut; |
| 36 | |
| 37 | const keys = createKeysFromShortcut(relevantShortcut); |
| 38 | useHotkeys( |
| 39 | keys, |
| 40 | (event, hotkeysEvent) => { |
| 41 | action(event); |
| 42 | }, |
| 43 | { |
| 44 | enabled: !disabled, |
| 45 | enableOnFormTags: enabledOnInputElements ?? relevantShortcut?.enabledOnInputElements, |
| 46 | enableOnContentEditable: enabledOnInputElements ?? relevantShortcut?.enabledOnInputElements, |
| 47 | } |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | function createKeysFromShortcut(shortcut: Shortcut | undefined) { |
| 52 | if (!shortcut) { |
no test coverage detected
searching dependent graphs…