mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* feat(studio): shortcut combos in the key resolver * feat(studio): every editor shortcut is a remappable combo * refactor(studio): playback keys dispatch through one table * fix(studio): combo parsing without backtracking, symbol keys match, fewer comments * style(studio): format the shortcut files * chore(studio): drop a doc comment the ratchet counts * chore(studio): drop a doc comment the ratchet counts * fix(studio): modifier combos fire for playback keys, caption guard and held stop key follow the map
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { useEffect, useCallback } from "react";
|
|
import { matchesKey } from "../player/components/studioShortcuts";
|
|
import { isTypingTarget } from "../utils/typingTarget";
|
|
|
|
interface KeyframeKeyboardOptions {
|
|
enabled: boolean;
|
|
onAddKeyframe?: () => void;
|
|
}
|
|
|
|
export function useKeyframeKeyboard({ enabled, onAddKeyframe }: KeyframeKeyboardOptions): void {
|
|
const handler = useCallback(
|
|
(e: KeyboardEvent) => {
|
|
if (!enabled || !onAddKeyframe) return;
|
|
if (isTypingTarget(document.activeElement)) return;
|
|
if (!matchesKey(e, "addKeyframe")) return;
|
|
// K is also playback's stop key: claiming it here keeps playback from also pausing.
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
onAddKeyframe();
|
|
},
|
|
[enabled, onAddKeyframe],
|
|
);
|
|
|
|
useEffect(() => {
|
|
if (!enabled) return;
|
|
// Capture phase: run before usePlaybackKeyboard's (bubble-phase) JKL handler
|
|
// so an active keyframe shortcut can claim the key.
|
|
window.addEventListener("keydown", handler, { capture: true });
|
|
return () => window.removeEventListener("keydown", handler, { capture: true });
|
|
}, [enabled, handler]);
|
|
}
|