Skip to content

Write HTML. Render video. Built for agents.

fix: keep caption shortcuts outside component

Miguel Ángel5fe53a0f9cb2
diff --git a/packages/studio/src/captions/components/CaptionOverlay.tsx b/packages/studio/src/captions/components/CaptionOverlay.tsx
index 78e72bc966..6725844b69 100644
--- a/packages/studio/src/captions/components/CaptionOverlay.tsx
+++ b/packages/studio/src/captions/components/CaptionOverlay.tsx
@@ -1,6 +1,7 @@
import { memo, useState, useCallback, useRef } from "react";
import { useCaptionStore } from "../store";
import { useMountEffect } from "../../hooks/useMountEffect";
+import { shouldHandleCaptionNudgeKey } from "../keyboard";
interface CaptionOverlayProps {
iframeRef: React.RefObject<HTMLIFrameElement | null>;
@@ -251,14 +252,6 @@ function syncToStore(segmentId: string, el: HTMLElement, iframeWin: Window) {
const HANDLE = 8;
const ROTATION_OFFSET = 20; // px above the selection box
-const CAPTION_NUDGE_KEYS = new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
-
-type CaptionNudgeKeyEvent = Pick<KeyboardEvent, "altKey" | "ctrlKey" | "metaKey" | "key">;
-
-export function shouldHandleCaptionNudgeKey(event: CaptionNudgeKeyEvent): boolean {
- if (event.metaKey || event.ctrlKey || event.altKey) return false;
- return CAPTION_NUDGE_KEYS.has(event.key);
-}
export const CaptionOverlay = memo(function CaptionOverlay({ iframeRef }: CaptionOverlayProps) {
const isEditMode = useCaptionStore((s) => s.isEditMode);
diff --git a/packages/studio/src/captions/components/CaptionOverlay.test.ts b/packages/studio/src/captions/keyboard.test.ts
similarity index 94%
rename from packages/studio/src/captions/components/CaptionOverlay.test.ts
rename to packages/studio/src/captions/keyboard.test.ts
index 886c4b80eb..ce6a6f4e6d 100644
--- a/packages/studio/src/captions/components/CaptionOverlay.test.ts
+++ b/packages/studio/src/captions/keyboard.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { shouldHandleCaptionNudgeKey } from "./CaptionOverlay";
+import { shouldHandleCaptionNudgeKey } from "./keyboard";
function mockKeyboardEvent(
key: string,
diff --git a/packages/studio/src/captions/keyboard.ts b/packages/studio/src/captions/keyboard.ts
new file mode 100644
index 0000000000..0c7ef81dfa
--- /dev/null
+++ b/packages/studio/src/captions/keyboard.ts
@@ -0,0 +1,8 @@
+const CAPTION_NUDGE_KEYS = new Set(["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"]);
+
+type CaptionNudgeKeyEvent = Pick<KeyboardEvent, "altKey" | "ctrlKey" | "metaKey" | "key">;
+
+export function shouldHandleCaptionNudgeKey(event: CaptionNudgeKeyEvent): boolean {
+ if (event.metaKey || event.ctrlKey || event.altKey) return false;
+ return CAPTION_NUDGE_KEYS.has(event.key);
+}