Files
hyperframes/packages/studio/src/hooks/linkShortcuts.ts
T
Miguel Ángel 9fa02badfc feat(studio): every editor and player shortcut is remappable (#6966)
* 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
2026-11-02 02:38:23 +00:00

44 lines
1.7 KiB
TypeScript

import { usePlayerStore } from "../player";
import type { TimelineEditCallbacks } from "../player/components/timelineCallbacks";
import { resolveLinkMenuItems } from "../player/components/clipMenuLinkItems";
import { isTypingTarget } from "../utils/typingTarget";
import { keyHint, matchesKey } from "../player/components/studioShortcuts";
export interface LinkShortcutCallbacks {
handleLinkEdit?: TimelineEditCallbacks["onLinkEdit"];
handleTimelineElementDeleteOnly?: TimelineEditCallbacks["onDeleteElementOnly"];
}
const ACTIONS = [
["linkToggle", "linkToggle"],
["detachAudio", "detachAudio"],
["deleteLinked", "deleteLinked"],
["deleteLinkedAlt", "deleteLinked"],
] as const;
const shortcutOf = (event: KeyboardEvent): string | null => {
const hit = ACTIONS.find(([action]) => matchesKey(event, action));
return hit ? keyHint(hit[1]) : null;
};
/** ⌘L unlink/link, ⌥⇧D detach audio, ⌥⌫ delete one linked clip — the clip menu's shortcuts. */
export function dispatchLinkShortcut(event: KeyboardEvent, cb: LinkShortcutCallbacks): boolean {
if (isTypingTarget(event.target)) return false;
const shortcut = shortcutOf(event);
if (!shortcut) return false;
const { elements, selectedElementId, selectedElementIds } = usePlayerStore.getState();
const element = elements.find((el) => (el.key ?? el.id) === selectedElementId);
if (!element) return false;
const item = resolveLinkMenuItems({
element,
elements,
selectedKeys: selectedElementIds,
onLinkEdit: cb.handleLinkEdit,
onDeleteElementOnly: cb.handleTimelineElementDeleteOnly,
}).find((candidate) => candidate.shortcut === shortcut);
if (!item) return false;
event.preventDefault();
item.run();
return true;
}