Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(preview): stop drawing captions twice in the preview

Etienne Lescot77dfc8a64135
diff --git a/src/components/ai-edition/CaptionLayer.tsx b/src/components/ai-edition/CaptionLayer.tsx
deleted file mode 100644
index db2914cf6..000000000
--- a/src/components/ai-edition/CaptionLayer.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-// The caption overlay in the preview.
-//
-// Deliberately NOT an `AnnotationOverlay`: a caption has no per-item identity to
-// select, nothing to drag and nothing to resize — its placement comes from the
-// caption settings, which the inspector owns. So this is a plain, pointer-events
-// -none band, which also means it can never steal a click from an annotation
-// sitting underneath it.
-//
-// It mirrors `annotationRenderer.renderText`'s box model (centred band, text
-// vertically centred, per-line background plate, 1.4 line-height) so what the
-// preview shows is what the export writes.
-
-import { useMemo } from "react";
-import { annotationFontSizePx } from "@/lib/ai-edition/annotationScale";
-import {
- type CaptionCue,
- type CaptionSettings,
- captionBackgroundCss,
- captionBandRect,
- captionCueAt,
-} from "@/lib/ai-edition/captions";
-
-interface CaptionLayerProps {
- cues: CaptionCue[];
- settings: CaptionSettings;
- /** Playhead in virtual (timeline) seconds — the same clock the cues use. */
- currentTimeSec: number;
- containerWidth: number;
- containerHeight: number;
-}
-
-export function CaptionLayer({
- cues,
- settings,
- currentTimeSec,
- containerWidth,
- containerHeight,
-}: CaptionLayerProps) {
- const currentTimeMs = Math.round(currentTimeSec * 1000);
- const cue = useMemo(() => captionCueAt(cues, currentTimeMs), [cues, currentTimeMs]);
-
- if (!settings.enabled || !cue || containerWidth <= 0 || containerHeight <= 0) return null;
-
- const rect = captionBandRect(settings);
- const background = captionBackgroundCss(settings);
-
- return (
- <div
- aria-hidden
- style={{
- position: "absolute",
- left: `${rect.x}%`,
- top: `${rect.y}%`,
- width: `${rect.width}%`,
- height: `${rect.height}%`,
- display: "flex",
- alignItems: "center",
- justifyContent:
- settings.textAlign === "left"
- ? "flex-start"
- : settings.textAlign === "right"
- ? "flex-end"
- : "center",
- overflow: "hidden",
- pointerEvents: "none",
- // Above every annotation, matching the export's z ordering.
- zIndex: 60,
- }}
- >
- <span
- style={{
- color: settings.color,
- backgroundColor: background,
- // Same rule as annotations (annotationScale.ts): the authored number is
- // pixels at a 1080-high frame, scaled by the box actually being drawn
- // into — so the preview is a scale model of the render instead of
- // showing one size on screen and another in the file.
- fontSize: `${annotationFontSizePx(settings.fontSize, containerHeight)}px`,
- fontFamily: settings.fontFamily,
- fontWeight: settings.fontWeight,
- textAlign: settings.textAlign,
- lineHeight: 1.4,
- // `clone` gives each wrapped line its own plate instead of one
- // ragged box around the whole paragraph — same as the exporter,
- // which draws the background per line.
- boxDecorationBreak: "clone",
- WebkitBoxDecorationBreak: "clone",
- padding: "0.1em 0.2em",
- borderRadius: 4,
- wordBreak: "break-word",
- whiteSpace: "pre-wrap",
- }}
- >
- {cue.text}
- </span>
- </div>
- );
-}
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsx
index 80800f309..99d73ba8c 100644
--- a/src/components/ai-edition/PreviewCanvas.tsx
+++ b/src/components/ai-edition/PreviewCanvas.tsx
@@ -40,7 +40,6 @@ import type {
AxcutZoomRegion,
} from "@/lib/ai-edition/schema";
import { useProjectStore } from "@/lib/ai-edition/store/projectStore";
-import { useCaptions } from "@/lib/ai-edition/store/useCaptions";
import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";
import { resolveActiveCameraTrack } from "@/lib/ai-edition/timeline/camera";
import { createPlaybackClockRef } from "@/lib/ai-edition/timeline/playback-clock";
@@ -55,7 +54,6 @@ import { classifyWallpaper, resolveImageWallpaperUrl } from "@/lib/wallpaper";
import { getCssClipPath } from "@/lib/webcamMaskShapes";
import { clamp, clamp01 } from "@/utils/math";
import { AnnotationLayer } from "./AnnotationLayer";
-import { CaptionLayer } from "./CaptionLayer";
import { NativeCompositorOverlay } from "./NativeCompositorOverlay";
import styles from "./NewEditorShell.module.css";
import { type VideoSource, VirtualPreview } from "./VirtualPreview";
@@ -110,7 +108,6 @@ export function PreviewCanvas(props: PreviewCanvasProps) {
const { settings, setLive, commit } = useEditorSettings();
// Captions are derived from the transcript, not passed down as regions — the
// preview reads them from the same façade the inspector writes to.
- const { cues: captionCues, settings: captionSettings } = useCaptions();
const document = useProjectStore((s) => s.document);
const assets = document?.assets ?? [];
const frameRef = useRef<HTMLDivElement | null>(null);
@@ -442,13 +439,6 @@ export function PreviewCanvas(props: PreviewCanvasProps) {
onCommit={props.onAnnotationCommit}
/>
) : null}
- <CaptionLayer
- cues={captionCues}
- settings={captionSettings}
- currentTimeSec={props.currentTimeSec}
- containerWidth={layout.screenRect.width}
- containerHeight={layout.screenRect.height}
- />
</div>
) : null}
{layout?.webcamRect && showWebcamSlot ? (