Skip to content

Write HTML. Render video. Built for agents.

fix(studio): the host can name Split's key on the toolbar and bind the clip menu's link keys (#4994)

Miguel Ángelb04081b376a3
diff --git a/packages/studio/src/components/TimelineToolbar.test.tsx b/packages/studio/src/components/TimelineToolbar.test.tsx
index 050c364613..a120f34ace 100644
--- a/packages/studio/src/components/TimelineToolbar.test.tsx
+++ b/packages/studio/src/components/TimelineToolbar.test.tsx
@@ -436,3 +436,28 @@ describe("TimelineToolbar — host right actions", () => {
act(() => root.unmount());
});
});
+
+describe("TimelineToolbar split hint", () => {
+ async function splitTooltip(props: Partial<React.ComponentProps<typeof TimelineToolbar>>) {
+ usePlayerStore.setState({
+ elements: [{ id: "a", domId: "a", tag: "div", start: 0, duration: 4, track: 0 }],
+ selectedElementId: "a",
+ currentTime: 2,
+ });
+ const { host, root } = renderToolbar(undefined, { onSplitElement: vi.fn(), ...props });
+ const button = host.querySelector<HTMLButtonElement>('button[aria-label="Split at playhead"]');
+ act(() => button?.focus());
+ await act(async () => {
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ });
+ const label = document.querySelector('[role="tooltip"]')?.textContent;
+ act(() => root.unmount());
+ usePlayerStore.setState({ elements: [], selectedElementId: null, currentTime: 0 });
+ return label;
+ }
+
+ it("names S unless the host binds Split to another key", async () => {
+ expect(await splitTooltip({})).toBe("Split at playhead (S)");
+ expect(await splitTooltip({ splitShortcut: "⌘B" })).toBe("Split at playhead (⌘B)");
+ });
+});
diff --git a/packages/studio/src/components/TimelineToolbar.tsx b/packages/studio/src/components/TimelineToolbar.tsx
index 56336b1f4f..0f317b623b 100644
--- a/packages/studio/src/components/TimelineToolbar.tsx
+++ b/packages/studio/src/components/TimelineToolbar.tsx
@@ -35,6 +35,8 @@ import { LinkedSelectionToggle } from "./LinkedSelectionToggle";
import { useProjectHasAudio } from "../utils/audioMeterMath";
import { canAddBeatAt, addBeatAtCompositionTime } from "../utils/beatEditActions";
import { isTypingTarget } from "../utils/typingTarget";
+import { SPLIT_SHORTCUT_HINT } from "../player/components/studioShortcuts";
+import type { TimelineProps } from "../player/components/TimelineTypes";
interface DomEditSessionSlice extends EnableKeyframesSession {
domEditSelection: DomEditSelection | null;
@@ -44,6 +46,7 @@ interface DomEditSessionSlice extends EnableKeyframesSession {
export interface TimelineToolbarProps {
domEditSession?: DomEditSessionSlice;
onSplitElement?: (element: TimelineElement, splitTime: number) => void;
+ splitShortcut?: TimelineProps["splitShortcut"];
history?: TimelineHistoryButtonsProps;
showHistory?: boolean;
showSelectAroundPlayhead?: boolean;
@@ -145,6 +148,7 @@ function useKeyframeToggle(session?: DomEditSessionSlice) {
export const TimelineToolbar = memo(function TimelineToolbar({
domEditSession,
onSplitElement,
+ splitShortcut = SPLIT_SHORTCUT_HINT,
history,
showHistory = true,
showSelectAroundPlayhead = true,
@@ -382,7 +386,7 @@ export const TimelineToolbar = memo(function TimelineToolbar({
<Tooltip
label={
canSplit
- ? "Split at playhead (S)"
+ ? `Split at playhead (${splitShortcut})`
: splittable
? "Move the playhead inside the clip to split"
: "Select a clip to split"
diff --git a/packages/studio/src/hooks/linkShortcuts.test.ts b/packages/studio/src/hooks/linkShortcuts.test.ts
index 93ab84c85d..8c7afe80ca 100644
--- a/packages/studio/src/hooks/linkShortcuts.test.ts
+++ b/packages/studio/src/hooks/linkShortcuts.test.ts
@@ -61,6 +61,22 @@ describe("dispatchLinkShortcut", () => {
expect(handleTimelineElementDeleteOnly).toHaveBeenCalledWith(video);
});
+ it("leaves ⌥⌫ to a text field the user is typing in", () => {
+ const video = clip("talk", "video", { muted: true, link: "lk-1" });
+ select([video, clip("talk-audio", "audio", { link: "lk-1" })], "talk");
+ const input = document.createElement("input");
+ document.body.append(input);
+ const event = key({ altKey: true, key: "Backspace", bubbles: true });
+ const handleTimelineElementDeleteOnly = vi.fn();
+ input.addEventListener("keydown", (e) =>
+ dispatchLinkShortcut(e, { handleLinkEdit: vi.fn(), handleTimelineElementDeleteOnly }),
+ );
+ input.dispatchEvent(event);
+ input.remove();
+ expect(handleTimelineElementDeleteOnly).not.toHaveBeenCalled();
+ expect(event.preventDefault).not.toHaveBeenCalled();
+ });
+
it("leaves the key alone when no link item applies", () => {
select([clip("title", "div")], "title");
const event = key({ metaKey: true, key: "l" });
diff --git a/packages/studio/src/hooks/linkShortcuts.ts b/packages/studio/src/hooks/linkShortcuts.ts
index 059ee8ff3a..f365b7ece1 100644
--- a/packages/studio/src/hooks/linkShortcuts.ts
+++ b/packages/studio/src/hooks/linkShortcuts.ts
@@ -1,6 +1,7 @@
import { usePlayerStore } from "../player";
import type { TimelineEditCallbacks } from "../player/components/timelineCallbacks";
import { resolveLinkMenuItems } from "../player/components/clipMenuLinkItems";
+import { isTypingTarget } from "../utils/typingTarget";
export interface LinkShortcutCallbacks {
handleLinkEdit?: TimelineEditCallbacks["onLinkEdit"];
@@ -22,6 +23,7 @@ function shortcutOf(event: KeyboardEvent): string | 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();
diff --git a/packages/studio/src/hooks/useAppHotkeys.ts b/packages/studio/src/hooks/useAppHotkeys.ts
index 0c3ca51b6b..199807a4d7 100644
--- a/packages/studio/src/hooks/useAppHotkeys.ts
+++ b/packages/studio/src/hooks/useAppHotkeys.ts
@@ -2,7 +2,6 @@ import { useCallback, useEffect, useRef } from "react";
import { usePlayerStore } from "../player";
import type { TimelineElement } from "../player";
import type { DomEditSelection } from "../components/editor/domEditing";
-import { isTypingTarget } from "../utils/typingTarget";
import { dispatchLinkShortcut, type LinkShortcutCallbacks } from "./linkShortcuts";
import { useCaptionStore } from "../captions/store";
import {
@@ -226,7 +225,7 @@ export function useAppHotkeys({
const handleAppKeyDown = useCallback((event: KeyboardEvent) => {
const cb = cbRef.current;
const key = event.key.toLowerCase();
- if (!isTypingTarget(event.target) && dispatchLinkShortcut(event, cb)) return;
+ if (dispatchLinkShortcut(event, cb)) return;
if (event.metaKey || event.ctrlKey) {
dispatchModifierKey(event, key, cb);
return;
diff --git a/packages/studio/src/index.ts b/packages/studio/src/index.ts
index f1a2e155d4..8fcc854080 100644
--- a/packages/studio/src/index.ts
+++ b/packages/studio/src/index.ts
@@ -7,6 +7,8 @@ export type { EditorShellProps } from "./components/EditorShell";
export { NLEPreview } from "./components/nle/NLEPreview";
export { DEFAULT_SHORTCUT_SECTIONS } from "./player/components/studioShortcuts";
export { ShortcutsButton } from "./player/components/ShortcutsPanel";
+export { dispatchLinkShortcut } from "./hooks/linkShortcuts";
+export type { LinkShortcutCallbacks } from "./hooks/linkShortcuts";
export type { ShortcutsButtonProps } from "./player/components/ShortcutsPanel";
export type { ShortcutHint, ShortcutSection } from "./player/components/studioShortcuts";
export { CompositionBreadcrumb } from "./components/nle/CompositionBreadcrumb";
diff --git a/packages/studio/src/timelineChromeExports.test.tsx b/packages/studio/src/timelineChromeExports.test.tsx
index c52f84edf0..c6383940bd 100644
--- a/packages/studio/src/timelineChromeExports.test.tsx
+++ b/packages/studio/src/timelineChromeExports.test.tsx
@@ -4,6 +4,7 @@ import { act } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
AudioMeterStrip,
+ dispatchLinkShortcut,
TimelineHistoryButtons,
TimelineToolbar,
useAudioMetersVisible as exportedAudioMetersVisible,
@@ -13,6 +14,7 @@ import {
} from "@hyperframes/studio";
import { installReactActEnvironment, mountReactHarness } from "./hooks/domSelectionTestHarness";
import { useAudioMetersVisible } from "./utils/audioMeterVisibility";
+import { dispatchLinkShortcut as localDispatchLinkShortcut } from "./hooks/linkShortcuts";
installReactActEnvironment();
@@ -52,6 +54,10 @@ describe("timeline chrome package exports, outside Studio's shell", () => {
await act(async () => root.unmount());
});
+ it("exports the clip menu's link shortcuts for a host's own key handler", () => {
+ expect(dispatchLinkShortcut).toBe(localDispatchLinkShortcut);
+ });
+
it("exports the meter visibility store a host toggles", () => {
expect(exportedAudioMetersVisible).toBe(useAudioMetersVisible);
exportedAudioMetersVisible.getState().setVisible(true);