Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat(editor): the readers count the pause an added word bought
EtienneLescota8faaad78a9a
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsxindex dea5a52d1..84133cfa7 100644--- a/src/components/ai-edition/NewEditorShell.tsx+++ b/src/components/ai-edition/NewEditorShell.tsx@@ -1474,6 +1474,7 @@ export function NewEditorShell() {speedRegions={tl.speedRegions}cameraFullscreenRegions={tl.cameraFullscreenRegions}trimRanges={tl.trimRanges}+ insertRanges={document?.timeline?.insertRanges ?? []}selectedZoomRegionId={tl.selection?.kind === "zoom" ? tl.selection.id : null}onZoomFocusChange={tl.updateZoomFocusLive}onZoomFocusCommit={() => void tl.commitZoomFocus()}diff --git a/src/components/ai-edition/Preview.tsx b/src/components/ai-edition/Preview.tsxindex cd6868e75..2753f9635 100644--- a/src/components/ai-edition/Preview.tsx+++ b/src/components/ai-edition/Preview.tsx@@ -5,6 +5,7 @@ import type {AxcutAnnotationRegion,AxcutAudioTrack,AxcutClip,+ AxcutInsertRange,AxcutTrimRange,AxcutZoomRegion,} from "@/lib/ai-edition/schema";@@ -33,6 +34,7 @@ interface PreviewProps {speedRegions?: SpeedRegion[];cameraFullscreenRegions?: CameraFullscreenRegion[];trimRanges?: AxcutTrimRange[];+ insertRanges?: AxcutInsertRange[];selectedZoomRegionId?: string | null;onZoomFocusChange?: (id: string, focus: ZoomFocus) => void;onZoomFocusCommit?: () => void;@@ -66,6 +68,7 @@ export function Preview({speedRegions,cameraFullscreenRegions,trimRanges,+ insertRanges,selectedZoomRegionId,onZoomFocusChange,onZoomFocusCommit,@@ -194,6 +197,7 @@ export function Preview({speedRegions={speedRegions}cameraFullscreenRegions={cameraFullscreenRegions}trimRanges={trimRanges}+ insertRanges={insertRanges}selectedZoomRegionId={selectedZoomRegionId}onZoomFocusChange={onZoomFocusChange}onZoomFocusCommit={onZoomFocusCommit}diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsxindex 150012b95..2fcd15d86 100644--- a/src/components/ai-edition/PreviewCanvas.tsx+++ b/src/components/ai-edition/PreviewCanvas.tsx@@ -36,6 +36,7 @@ import type {AxcutAnnotationRegion,AxcutAudioTrack,AxcutClip,+ AxcutInsertRange,AxcutTrimRange,AxcutZoomRegion,} from "@/lib/ai-edition/schema";@@ -75,6 +76,7 @@ interface PreviewCanvasProps {speedRegions?: SpeedRegion[];cameraFullscreenRegions?: CameraFullscreenRegion[];trimRanges?: AxcutTrimRange[];+ insertRanges?: AxcutInsertRange[];selectedZoomRegionId?: string | null;onZoomFocusChange?: (id: string, focus: ZoomFocus) => void;onZoomFocusCommit?: () => void;diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsxindex 326bbd642..aed97cc4c 100644--- a/src/components/ai-edition/VirtualPreview.tsx+++ b/src/components/ai-edition/VirtualPreview.tsx@@ -12,6 +12,7 @@ import {import type {AxcutAudioTrack,AxcutClip,+ AxcutInsertRange,AxcutTrimRange,AxcutZoomRegion,} from "@/lib/ai-edition/schema";@@ -201,6 +202,8 @@ interface VirtualPreviewProps {zoomRegions?: AxcutZoomRegion[];speedRegions?: SpeedRegion[];trimRanges?: AxcutTrimRange[];+ /** The pauses added words created — they lengthen playback, they do not cut it. */+ insertRanges?: AxcutInsertRange[];seekTarget?: { timeSec: number; isSource?: boolean; requestId: number } | null;onTimeChange?: (timeSec: number) => void;onLoadedMetadata?: (@@ -247,6 +250,7 @@ export function VirtualPreview({zoomRegions = [],speedRegions = [],trimRanges = [],+ insertRanges = [],seekTarget,onTimeChange,onLoadedMetadata,@@ -554,8 +558,8 @@ export function VirtualPreview({// source time to a RAW virtual time that jumps discontinuously by exactly the trim's// width the moment the video itself jumps — matching the marker's own pixel span.const playbackClips = useMemo(- () => resolvePlaybackSegments(clips, trimRanges),- [clips, trimRanges],+ () => resolvePlaybackSegments(clips, trimRanges, insertRanges),+ [clips, trimRanges, insertRanges],);const playbackClipsRef = useRef(playbackClips);playbackClipsRef.current = playbackClips;diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex 6476d6406..4a8f642fd 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -50,6 +50,12 @@ import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";import { hasAnyClipWithCamera } from "@/lib/ai-edition/timeline/camera";import { formatSec } from "@/lib/ai-edition/timeline/format";+import {+ expandRawSec,+ type RulerInsert,+ rulerInserts,+ totalInsertedSec,+} from "@/lib/ai-edition/timeline/inserted-time";import {newRegionDurationSec,setTimelineScale,@@ -219,6 +225,10 @@ interface RulerTick {interface PlayheadOverlayProps {/** Full timeline length in seconds — the denominator for the playhead's percentage. */totalSec: number;+ /** The pauses added words created. `currentTimeSec` is a STORED second; the ruler it is+ * drawn on counts the pauses, so it has to be placed through them or it drifts from+ * the clips by the whole added time. */+ inserts: readonly RulerInsert[];/** Live scrub position, when a drag is in flight. Takes precedence over the store. */overrideTimeSec: number | null;canvasStyle: React.CSSProperties;@@ -244,13 +254,14 @@ interface PlayheadOverlayProps {*/const PlayheadOverlay = memo(function PlayheadOverlay({totalSec,+ inserts,overrideTimeSec,canvasStyle,onPointerDown,playheadRef,}: PlayheadOverlayProps) {const storeTimeSec = useProjectStore((s) => s.currentTimeSec);- const pct = ((overrideTimeSec ?? storeTimeSec) / totalSec) * 100;+ const pct = (expandRawSec(overrideTimeSec ?? storeTimeSec, inserts) / totalSec) * 100;return (<div className={styles.tlPlayheadLayer} aria-hidden><div className={styles.tlCanvas} style={canvasStyle}>@@ -631,15 +642,26 @@ export function V4Timeline({// clicked instead of looking like it worked. Same question, same helper as the Layout// pane: is a camera attached anywhere on this timeline?const hasAnyCamera = useMemo(() => hasAnyClipWithCamera(tl.assets, clips), [tl.assets, clips]);+ // The pauses added words created, placed on the ruler. Everything below measures the+ // EXPANDED ruler — stored clip geometry plus the time those pauses add — because that+ // is the film's real length and the one the playhead runs along. Stored geometry is+ // never rewritten for this: only what is drawn moves.+ // `?? []` because the key is additive: a document written before it has no pauses.+ const inserts = useMemo(+ () => rulerInserts(tl.insertRanges ?? [], clips),+ [tl.insertRanges, clips],+ );const total = useMemo(() =>Math.max(1,- clips.reduce((m, c) => Math.max(m, c.timelineEndSec), 0),+ clips.reduce((m, c) => Math.max(m, c.timelineEndSec), 0) + totalInsertedSec(inserts),),- [clips],+ [clips, inserts],);const pctOf = useCallback((sec: number) => (sec / total) * 100, [total]);+ /** Stored raw seconds → a percentage of the expanded ruler. */+ const pctAt = useCallback((sec: number) => pctOf(expandRawSec(sec, inserts)), [pctOf, inserts]);const showLanes = variant === "edit";// The visible fraction of the timeline, and what one second is worth on screen@@ -1594,8 +1616,10 @@ export function V4Timeline({compact ? ` ${styles.lanePillCompact}` : ""}${seg.interactive && isPillSelected(p.id) ? ` ${styles.lanePillSel}` : ""}`}style={{- left: `${pctOf(seg.segStart)}%`,- width: `${pctOf(durSec)}%`,+ left: `${pctAt(seg.segStart)}%`,+ // Measured on the expanded ruler at BOTH ends: a region straddling a pause+ // covers it, so its box has to grow by that pause and not merely slide.+ width: `${pctOf(expandRawSec(seg.segEnd, inserts) - expandRawSec(seg.segStart, inserts))}%`,transform: seg.shiftPx ? `translateX(${seg.shiftPx}px)` : undefined,transition: !clipDrag? undefined@@ -2006,7 +2030,7 @@ export function V4Timeline({<divkey={tick.sec}className={`${styles.tlTick}${tick.major ? ` ${styles.tlTickMajor}` : ""}`}- style={{ left: `${pctOf(tick.sec)}%` }}+ style={{ left: `${pctAt(tick.sec)}%` }}>{tick.major ? (<span className={styles.tlTickLabel}>{fmtTick(tick.sec, rulerTicks.step)}</span>@@ -2153,6 +2177,12 @@ export function V4Timeline({>{clips.map((c, i) => {const dur = c.timelineEndSec - c.timelineStartSec;+ // On the expanded ruler the box also carries whatever pauses fall+ // inside it — the film really does stay on this clip's frame for+ // them, so they belong to its box rather than between boxes.+ const boxStart = expandRawSec(c.timelineStartSec, inserts);+ const boxEnd = expandRawSec(c.timelineEndSec, inserts);+ const boxLen = boxEnd - boxStart;const asset = tl.assets.find((a) => a.id === c.assetId);const clipVideoUrl = videoSources.find((v) => v.id === c.assetId)?.src;const selected = tl.clipSelection === c.id;@@ -2180,12 +2210,12 @@ export function V4Timeline({dragging ? ` ${styles.tlClipDragging}` : ""}`}style={{- left: `${pctOf(c.timelineStartSec)}%`,+ left: `${pctOf(boxStart)}%`,// Minus the gutter that separates two cards (it used to be the// flex row's `gap`). A clip shorter than the gutter lands on// .tlClip's 1px min-width instead of collapsing — same rule as// the lane pills above.- width: `calc(${pctOf(dur)}% - ${CLIP_GUTTER_PX}px)`,+ width: `calc(${pctOf(boxLen)}% - ${CLIP_GUTTER_PX}px)`,transform: clipTransform,}}onPointerDown={(e) => startClipDrag(e, c)}@@ -2228,25 +2258,41 @@ export function V4Timeline({{tl.assets.find((a) => a.id === c.assetId)?.label ?? c.assetId}</span></div>- {(insertedWordsByClip.get(c.id) ?? []).map(({ word, atPct }) => (- <button- key={word.id}- type="button"- data-no-clip-drag- data-inserted-word={word.id}- className={styles.tlClipInsert}- style={{ left: `${atPct}%` }}- title={t("toolbar.addedWord", { word: word.text })}- aria-label={t("toolbar.addedWord", { word: word.text })}- onPointerDown={(e) => e.stopPropagation()}- onClick={(e) => {- // Jump to the moment the added text sits on. The clip box- // underneath would otherwise take this as a selection.- e.stopPropagation();- setCurrentTime(c.timelineStartSec + (word.startSec - c.sourceStartSec));- }}- />- ))}+ {(insertedWordsByClip.get(c.id) ?? []).map(({ word, atPct }) => {+ // A word whose pause the film actually holds gets a BAND as wide+ // as the time it adds — that width is the added time, drawn. One+ // that fitted in silence already there adds nothing and stays the+ // hairline it was: there is nothing to show.+ const pause = inserts.find((ins) => ins.wordId === word.id);+ const left = pause+ ? ((expandRawSec(pause.atRawSec, inserts) - boxStart) / boxLen) * 100+ : atPct;+ const width = pause ? (pause.durationSec / boxLen) * 100 : 0;+ return (+ <button+ key={word.id}+ type="button"+ data-no-clip-drag+ data-inserted-word={word.id}+ data-inserted-sec={pause?.durationSec ?? 0}+ className={styles.tlClipInsert}+ style={+ width > 0+ ? { left: `${left}%`, width: `${width}%`, marginLeft: 0 }+ : { left: `${left}%` }+ }+ title={t("toolbar.addedWord", { word: word.text })}+ aria-label={t("toolbar.addedWord", { word: word.text })}+ onPointerDown={(e) => e.stopPropagation()}+ onClick={(e) => {+ // Jump to the moment the added text sits on. The clip box+ // underneath would otherwise take this as a selection.+ e.stopPropagation();+ setCurrentTime(c.timelineStartSec + (word.startSec - c.sourceStartSec));+ }}+ />+ );+ })}{selected ? (<buttontype="button"@@ -2282,6 +2328,7 @@ export function V4Timeline({{showLanes ? (<PlayheadOverlaytotalSec={total}+ inserts={inserts}overrideTimeSec={scrubbingTimeSec}canvasStyle={canvasStyle}onPointerDown={startScrub}diff --git a/src/lib/ai-edition/captions/captions.test.ts b/src/lib/ai-edition/captions/captions.test.tsindex ce3d4a961..837736af3 100644--- a/src/lib/ai-edition/captions/captions.test.ts+++ b/src/lib/ai-edition/captions/captions.test.ts@@ -650,3 +650,52 @@ describe("translated caption layout", () => {);});});++// ─── Captions across an added word's pause ───────────────────────+// The pause lengthens the ruler, so every line after it slides — and the line the pause+// exists FOR has to stay on screen through it rather than going dark over the one moment+// an added word is there for.++describe("captions and a pause", () => {+ function withPause(): AxcutDocument {+ const base = doc();+ return {+ ...base,+ timeline: {+ ...base.timeline,+ insertRanges: [+ {+ id: "ins_1",+ assetId: "asset-1",+ // Inside "hello there friend" (0–2s), so the line covers it.+ atSec: 1.2,+ durationSec: 0.5,+ wordId: "synth_1",+ reason: "",+ origin: "user" as const,+ },+ ],+ },+ };+ }++ it("keeps the covering line up through the pause instead of cutting it short", () => {+ const before = deriveCaptionCues(doc(), ON, {});+ const after = deriveCaptionCues(withPause(), ON, {});+ const line = (cues: typeof before) => cues.find((cue) => cue.text.includes("hello"));+ expect(line(after)?.startMs).toBe(line(before)?.startMs);+ // Half a second longer: exactly the pause it now spans.+ expect((line(after)?.endMs ?? 0) - (line(before)?.endMs ?? 0)).toBe(500);+ });++ it("slides everything after the pause along by it", () => {+ const before = deriveCaptionCues(doc(), ON, {});+ const after = deriveCaptionCues(withPause(), ON, {});+ const later = (cues: typeof before) => cues.find((cue) => cue.text.includes("goodbye"));+ expect((later(after)?.startMs ?? 0) - (later(before)?.startMs ?? 0)).toBe(500);+ });++ it("is unchanged when the project has no pauses", () => {+ expect(deriveCaptionCues(doc(), ON, {})).toEqual(deriveCaptionCues(doc(), ON, {}));+ });+});diff --git a/src/lib/ai-edition/captions/cues.ts b/src/lib/ai-edition/captions/cues.tsindex c3287ebcb..b4dfa7677 100644--- a/src/lib/ai-edition/captions/cues.ts+++ b/src/lib/ai-edition/captions/cues.ts@@ -23,6 +23,7 @@ import {} from "@/lib/captioning/annotationsFromCaptions";import type { CaptionSegment } from "@/lib/captioning/transcribe";import type { AxcutClip, AxcutDocument, AxcutTranscript } from "../schema";+import { expandRawSec, type RulerInsert, rulerInserts } from "../timeline/inserted-time";import {type CaptionAnchorV,type CaptionSettings,@@ -157,6 +158,7 @@ export function sourceSpanToTimelineSpans(startSec: number,endSec: number,clips: AxcutClip[],+ inserts: readonly RulerInsert[] = [],): Array<{ startSec: number; endSec: number }> {const out: Array<{ startSec: number; endSec: number }> = [];for (const clip of clips) {@@ -170,7 +172,15 @@ export function sourceSpanToTimelineSpans(endSec: clip.timelineStartSec + (e - clip.sourceStartSec),});}- return out;+ // Onto the ruler the viewer actually sees. Expanding BOTH ends does the whole job:+ // a line after a pause slides along by it, and a line that covers the held moment+ // has only its end pushed out — so it stays on screen through the pause instead of+ // going dark over the one moment an added word exists for.+ if (inserts.length === 0) return out;+ return out.map((span) => ({+ startSec: expandRawSec(span.startSec, inserts),+ endSec: expandRawSec(span.endSec, inserts),+ }));}/**@@ -189,6 +199,9 @@ export function deriveCaptionCues(if (clips.length === 0) return [];const transcripts = new Map(document.transcripts.map((t) => [t.assetId, t]));+ // `?? []` because the key is additive: a document written before it — or a hand-built+ // one that never went through the schema — simply has no pauses.+ const inserts = rulerInserts(document.timeline.insertRanges ?? [], clips);// A transcript is only projected once per asset even when several clips draw// from it (line grouping is the expensive part, clipping is cheap).const linesByAsset = new Map<string, CaptionSegment[]>();@@ -205,7 +218,13 @@ export function deriveCaptionCues(for (const line of lines) {const text = line.text.trim();if (!text) continue;- for (const span of sourceSpanToTimelineSpans(assetId, line.startSec, line.endSec, clips)) {+ for (const span of sourceSpanToTimelineSpans(+ assetId,+ line.startSec,+ line.endSec,+ clips,+ inserts,+ )) {const startMs = Math.round(span.startSec * 1000);const endMs = Math.max(Math.round(span.endSec * 1000), startMs + 1);cues.push({ id: `caption-${n++}`, startMs, endMs, text });diff --git a/src/lib/ai-edition/document/timeline.test.ts b/src/lib/ai-edition/document/timeline.test.tsindex 02b3d5244..4774c6517 100644--- a/src/lib/ai-edition/document/timeline.test.ts+++ b/src/lib/ai-edition/document/timeline.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";import {type AxcutClip,type AxcutDocument,+ type AxcutInsertRange,type AxcutTrimRange,axcutSchemaVersion,} from "../schema";@@ -1745,3 +1746,89 @@ describe("projectRawTimelineSecToPlayback with speed regions", () => {expect(projectRawTimelineSecToPlayback([clip], [], 4, speed)).toBeCloseTo(4, 6);});});++// ─── The pause an added word bought ──────────────────────────────+// Created time only exists once playback honours it. These pin the one thing the record+// is for: the stream really does stay on the held frame, and the film really is longer.++describe("resolvePlaybackSegments with insert ranges", () => {+ const CLIPS: AxcutClip[] = [+ {+ id: "c1",+ assetId: "a1",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ wordRefs: [],+ origin: "user",+ reason: "",+ },+ ];+ const insert = (overrides: Partial<AxcutInsertRange> = {}): AxcutInsertRange => ({+ id: "ins_1",+ assetId: "a1",+ atSec: 10,+ durationSec: 0.5,+ wordId: "synth_1",+ reason: "held",+ origin: "user",+ ...overrides,+ });++ it("holds the frame where the pause sits, and lengthens the stream by it", () => {+ const segments = resolvePlaybackSegments(CLIPS, [], [insert()]);+ expect(segments).toHaveLength(2);+ expect(segments[1]).toMatchObject({+ sourceStartSec: 10,+ sourceEndSec: 10,+ heldSec: 0.5,+ timelineStartSec: 10,+ timelineEndSec: 10.5,+ });+ });++ it("changes nothing when there is no pause", () => {+ expect(resolvePlaybackSegments(CLIPS, [], [])).toHaveLength(1);+ });++ // The usual case, and the one the first cut of this missed: a pause sits at the end of+ // the word it follows, which is almost never a boundary a trim happened to leave.+ it("cuts the clip open where a pause falls in the MIDDLE of it", () => {+ const segments = resolvePlaybackSegments(CLIPS, [], [insert({ atSec: 2.5 })]);+ expect(segments.map((s) => [s.sourceStartSec, s.sourceEndSec, s.heldSec])).toEqual([+ [0, 2.5, undefined],+ [2.5, 2.5, 0.5],+ [2.5, 10, undefined],+ ]);+ // 10s of film plus half a second of held frame.+ expect(segments[2].timelineEndSec).toBeCloseTo(10.5, 5);+ });++ // The moment the pause holds is not in the film any more, so neither is the pause.+ it("drops a pause whose moment a trim removed", () => {+ const trims: AxcutTrimRange[] = [+ { id: "t1", assetId: "a1", startSec: 4, endSec: 10, origin: "user", reason: "" },+ ];+ const segments = resolvePlaybackSegments(CLIPS, trims, [insert()]);+ expect(segments.some((s) => s.heldSec !== undefined)).toBe(false);+ });++ it("places a pause inside a clip between the halves a trim left", () => {+ const trims: AxcutTrimRange[] = [+ { id: "t1", assetId: "a1", startSec: 4, endSec: 6, origin: "user", reason: "" },+ ];+ const segments = resolvePlaybackSegments(CLIPS, trims, [insert({ atSec: 4 })]);+ expect(segments.map((s) => s.heldSec)).toEqual([undefined, 0.5, undefined]);+ // The stream is the kept film plus the pause: 4s + 0.5s + 4s.+ expect(segments[segments.length - 1].timelineEndSec).toBeCloseTo(8.5, 5);+ });++ it("never writes the held flag onto a stored clip", () => {+ // The field lives on the derived segment only; that is the whole difference from+ // the attempt that made clips for it.+ const segments = resolvePlaybackSegments(CLIPS, [], [insert()]);+ expect(CLIPS[0]).not.toHaveProperty("heldSec");+ expect(segments[0]).not.toHaveProperty("heldSec");+ });+});diff --git a/src/lib/ai-edition/document/timeline.ts b/src/lib/ai-edition/document/timeline.tsindex 987e91dc2..ee46a6cc2 100644--- a/src/lib/ai-edition/document/timeline.ts+++ b/src/lib/ai-edition/document/timeline.ts@@ -3,7 +3,24 @@// (store, exporter, agent) feeds an AxcutDocument and gets back intervals// or a new document with updated clips.-import type { AxcutClip, AxcutDocument, AxcutTranscript, AxcutTrimRange } from "../schema";+import type {+ AxcutClip,+ AxcutDocument,+ AxcutInsertRange,+ AxcutTranscript,+ AxcutTrimRange,+} from "../schema";++/**+ * What `resolvePlaybackSegments` returns: a clip-shaped slice of playable film, plus the+ * one thing a stored clip can never carry — `heldSec`, the pause an added word created.+ *+ * A held segment's source window is the single frame it shows; its LENGTH is `heldSec`.+ * The field lives only on this derived shape, never on `clipSchema`, so nothing can write+ * one to disk — which is the whole difference from the attempt that made clips for it.+ */+export type PlaybackSegment = AxcutClip & { heldSec?: number };+import {anchoredToRawSpanSec,anchorRegionsWithDerivedMs,@@ -164,10 +181,32 @@ export function subtractInterval(intervals: Interval[], cut: Interval): Intervalexport function resolvePlaybackSegments(clips: AxcutClip[],trimRanges: AxcutTrimRange[],-): AxcutClip[] {+ insertRanges: readonly AxcutInsertRange[] = [],+): PlaybackSegment[] {const ordered = [...clips].sort((a, b) => a.timelineStartSec - b.timelineStartSec);- const result: AxcutClip[] = [];+ const result: PlaybackSegment[] = [];let timelineCursor = 0;+ // The pauses added words need, in the order they will be met. Consumed as the walk+ // passes each one's moment, so a pause inside a span a trim removed is never reached —+ // which is right: the moment it holds is not in the film any more.+ const pending = [...insertRanges].sort((a, b) => a.atSec - b.atSec);+ const holdAt = (clip: AxcutClip, atSec: number): PlaybackSegment | null => {+ const insert = pending.find(+ (range) => range.assetId === clip.assetId && Math.abs(range.atSec - atSec) < 1e-6,+ );+ if (!insert) return null;+ pending.splice(pending.indexOf(insert), 1);+ return {+ ...clip,+ id: `${clip.id}__hold_${insert.id}`,+ sourceStartSec: atSec,+ sourceEndSec: atSec,+ timelineStartSec: 0,+ timelineEndSec: 0,+ heldSec: insert.durationSec,+ reason: insert.reason,+ };+ };for (const clip of ordered) {const sourceEnd = clip.sourceEndSec ?? clip.sourceStartSec;if (sourceEnd <= clip.sourceStartSec) {@@ -186,18 +225,52 @@ export function resolvePlaybackSegments(if (!trimAppliesToClip(trim, clip)) continue;kept = subtractInterval(kept, { startSec: trim.startSec, endSec: trim.endSec });}- kept.forEach((iv, i) => {- const dur = iv.endSec - iv.startSec;- if (dur <= 0) return;+ // A pause sits at the END of the word it follows, which is almost never a boundary a+ // trim happened to leave. So each kept span is cut at the moments it holds, and the+ // held frame goes between the halves: the stream plays up to that frame, stays on it+ // for the pause, then carries on — which is what makes the film longer.+ const pieces: Array<{ startSec: number; endSec: number; holdAtEnd: boolean }> = [];+ for (const iv of kept) {+ const moments = pending+ .filter(+ (range) =>+ range.assetId === clip.assetId &&+ range.atSec > iv.startSec + 1e-6 &&+ range.atSec <= iv.endSec + 1e-6,+ )+ .map((range) => range.atSec)+ .sort((a, b) => a - b);+ let from = iv.startSec;+ for (const at of moments) {+ pieces.push({ startSec: from, endSec: Math.min(at, iv.endSec), holdAtEnd: true });+ from = Math.min(at, iv.endSec);+ }+ if (iv.endSec - from > 1e-6 || pieces.length === 0) {+ pieces.push({ startSec: from, endSec: iv.endSec, holdAtEnd: false });+ }+ }+ pieces.forEach((piece, i) => {+ const dur = piece.endSec - piece.startSec;+ if (dur > 0) {+ result.push({+ ...clip,+ id: pieces.length === 1 ? clip.id : `${clip.id}_seg${i + 1}`,+ sourceStartSec: piece.startSec,+ sourceEndSec: piece.endSec,+ timelineStartSec: timelineCursor,+ timelineEndSec: timelineCursor + dur,+ });+ timelineCursor += dur;+ }+ if (!piece.holdAtEnd) return;+ const hold = holdAt(clip, piece.endSec);+ if (!hold) return;result.push({- ...clip,- id: kept.length === 1 ? clip.id : `${clip.id}_seg${i + 1}`,- sourceStartSec: iv.startSec,- sourceEndSec: iv.endSec,+ ...hold,timelineStartSec: timelineCursor,- timelineEndSec: timelineCursor + dur,+ timelineEndSec: timelineCursor + (hold.heldSec ?? 0),});- timelineCursor += dur;+ timelineCursor += hold.heldSec ?? 0;});}return result;diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.tsindex d00d8e59f..cb514d15b 100644--- a/src/lib/ai-edition/store/useTimeline.ts+++ b/src/lib/ai-edition/store/useTimeline.ts@@ -1443,6 +1443,9 @@ export function useTimeline() {zoomRegions: document?.zoomRanges ?? [],trimRanges: document?.timeline.trimRanges ?? [],audioTracks: document?.audioTracks ?? [],+ // The pauses added words created. The ruler counts them; nothing else in the+ // timeline store writes them (see `document/transcript.ts`).+ insertRanges: document?.timeline.insertRanges ?? [],annotationRegions: (document?.annotations ?? []) as unknown as AnnotationRegion[],speedRegions,cameraFullscreenRegions,diff --git a/src/lib/ai-edition/timeline/timelineMap.ts b/src/lib/ai-edition/timeline/timelineMap.tsindex b98601a03..507126f5c 100644--- a/src/lib/ai-edition/timeline/timelineMap.ts+++ b/src/lib/ai-edition/timeline/timelineMap.ts@@ -17,6 +17,7 @@// against the COMPRESSED segment layout, which slips every region after a trim// forward by the trimmed duration.+import type { PlaybackSegment } from "../document/timeline";import type { AxcutClip } from "../schema";import { ventilateSpanAcrossClips } from "./region-ventilation";import { findRawClipForSegment, getRawVirtualStartTime } from "./virtual-preview";@@ -399,11 +400,15 @@ export function anchorRegionsWithDerivedMs<* the gap.*/export function segmentRawSpanSec(- segment: AxcutClip,+ segment: PlaybackSegment,rawClips: AxcutClip[],): { startSec: number; endSec: number } {const startSec = getRawVirtualStartTime(segment, rawClips);- const lenSec = (segment.sourceEndSec ?? segment.sourceStartSec) - segment.sourceStartSec;+ // A held segment's source window is the single frame it shows, so its source length+ // is zero — its RAW span is the pause it carries. Without this the playhead could+ // never be inside it and would step straight over the pause.+ const lenSec =+ segment.heldSec ?? (segment.sourceEndSec ?? segment.sourceStartSec) - segment.sourceStartSec;return { startSec, endSec: startSec + lenSec };}@@ -559,7 +564,7 @@ export function projectRegionsToSource<T extends { id: string; startMs: number; endMs: number } & RegionClipAnchor,>(regions: T[],- visibleSegments: AxcutClip[],+ visibleSegments: PlaybackSegment[],rawClips: AxcutClip[],makeId: () => string,): (T & { clipIndex?: number; underTrim?: boolean })[] {@@ -639,7 +644,7 @@ export function projectRegionsToSource<export interface NativePosition {/** The trim-narrowed playback segment (from `visibleSegments`) that is active. */- clip: AxcutClip;+ clip: PlaybackSegment;/** Its index in `visibleSegments`, matching `SceneDescription.clips` / native `clip_index`. */clipIndex: number;/** Screen-source seconds the native decoder should present for this segment. */@@ -675,7 +680,7 @@ const NATIVE_EOF_MARGIN_SEC = 0.033;*/export function resolveNativePosition(rawSec: number,- visibleSegments: AxcutClip[],+ visibleSegments: PlaybackSegment[],rawClips: AxcutClip[],): NativePosition | null {if (!Number.isFinite(rawSec) || visibleSegments.length === 0) return null;@@ -689,6 +694,13 @@ export function resolveNativePosition(if (index < 0) return positionUnderCut(rawSec, visibleSegments, rawClips);const seg = visibleSegments[index];+ // Inside a pause the source clock does not advance: the whole point of the segment+ // is created time over one held frame. Clamping here is what stops the raw-playhead+ // delta — which DOES advance through the pause — from pushing the decoder past the+ // held frame into the content that belongs after it.+ if (seg.heldSec !== undefined) {+ return { clip: seg, clipIndex: index, sourceTimeSec: seg.sourceStartSec };+ }const segSourceEnd = seg.sourceEndSec ?? seg.sourceStartSec;const unclamped = seg.sourceStartSec + (rawSec - spans[index].startSec);const maxSource = Math.max(seg.sourceStartSec, segSourceEnd - NATIVE_EOF_MARGIN_SEC);diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 0d214831b..69bfa1016 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -514,7 +514,11 @@ function clipAssetIsResolvable(export function resolveVisibleClips(document: AxcutDocument): AxcutClip[] {const assetById = new Map(document.assets.map((a) => [a.id, a]));- return resolvePlaybackSegments(document.timeline.clips, document.timeline.trimRanges)+ return resolvePlaybackSegments(+ document.timeline.clips,+ document.timeline.trimRanges,+ document.timeline.insertRanges,+ ).sort((a, b) => a.timelineStartSec - b.timelineStartSec).filter((clip) => clipAssetIsResolvable(clip, assetById));}diff --git a/src/native/useNativePlaybackSync.ts b/src/native/useNativePlaybackSync.tsindex 64e877b63..f1ab884ed 100644--- a/src/native/useNativePlaybackSync.ts+++ b/src/native/useNativePlaybackSync.ts@@ -41,6 +41,12 @@ export function useNativePlaybackSync();const activeClipId = activePosition?.clip.id ?? null;const sourceTimeSec = activePosition?.sourceTimeSec ?? null;+ // A pause holds ONE frame for its whole length. Free-running the decoder through it+ // would play what comes after instead, and the app clock — which does traverse the+ // pause — would then re-seek on the drift and stutter. Pausing the decoder is what+ // makes the pause a pause; the webcam holds with the screen because both derive+ // from the one asset source clock the pause stops advancing.+ const held = activePosition?.clip.heldSec !== undefined;// Reactive "is a native view active?" so activation mid-session re-pushes the// current transport/playhead (time & playing aren't memoised in the store).@@ -54,8 +60,8 @@ export function useNativePlaybackSync(if (!active) {return;}- setNativePlaying(playing);- }, [active, playing]);+ setNativePlaying(playing && !held);+ }, [active, playing, held]);// Scrub/step while paused OR periodic resync during playback when drift > 100msconst lastSyncedSourceTimeRef = useRef<number | null>(null);@@ -68,6 +74,16 @@ export function useNativePlaybackSync(}const now = performance.now();+ // Inside a pause while playing: the decoder is parked on the held frame (see the+ // transport effect). Refresh the drift refs every run so the check never reads a+ // correctly-frozen source clock as divergence and fights itself with seeks.+ if (playing && held) {+ setNativeTime(sourceTimeSec);+ lastSyncedSourceTimeRef.current = sourceTimeSec;+ lastSyncedWallTimeRef.current = now;+ return;+ }+// When clip changes, let setActiveClip handle the atomic clip-switch-and-seek.if (lastActiveClipIdRef.current !== activeClipId) {lastActiveClipIdRef.current = activeClipId;@@ -95,5 +111,5 @@ export function useNativePlaybackSync(lastSyncedSourceTimeRef.current = sourceTimeSec;lastSyncedWallTimeRef.current = now;}- }, [active, playing, activeClipId, sourceTimeSec]);+ }, [active, playing, held, activeClipId, sourceTimeSec]);}