Skip to content

Commit

Permalink
more precise shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Jan 10, 2025
1 parent 7bba4db commit fd1664f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/ui/src/hooks/useGlobalShortcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export type Shortcut = {
//TODO: Make sure that keyboard shortcut only works when exact modifiers are pressed. This means checking for altKey and controlKey as well.
function eventMatchesShortcut(event: KeyboardEvent, shortcut: Shortcut) {
if (
(shortcut.shiftKey && !event.shiftKey) ||
(shortcut.metaKey && !event.metaKey) ||
(shortcut.shiftKey ?? false) !== event.shiftKey ||
(shortcut.metaKey ?? false) !== event.metaKey ||
event.key.toLowerCase() !== shortcut.key.toLowerCase()
) {
return false;
Expand Down Expand Up @@ -41,6 +41,7 @@ export function useGlobalShortcuts(shortcuts: [Shortcut, () => void][]) {
// memoize it to prevent unnecessary effect executions. That said, this should run quickly anyway.
}, [shortcuts]);
}

export function useGlobalShortcut(shortcut: Shortcut, act: () => void) {
// Explicitly type the memoized value to ensure it's recognized as an array of [Shortcut, () => void] tuples
const shortcuts = useMemo<[Shortcut, () => void][]>(
Expand Down

0 comments on commit fd1664f

Please sign in to comment.