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
fix(timeline): the insertions are a required argument, and the compiler found the rest
EtienneLescotd610e739a26a
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsxindex 2fcd15d86..07a526f45 100644--- a/src/components/ai-edition/PreviewCanvas.tsx+++ b/src/components/ai-edition/PreviewCanvas.tsx@@ -63,6 +63,9 @@ import { type VideoSource, VirtualPreview } from "./VirtualPreview";import { WebcamOverlay } from "./WebcamOverlay";import { ZoomFocusOverlay } from "./ZoomFocusOverlay";+/** Stable identity, so the memos are not invalidated every render by a fresh `[]`. */+const EMPTY_INSERT_RANGES: readonly AxcutInsertRange[] = [];+type BlurData = NonNullable<AxcutAnnotationRegion["blurData"]>;interface PreviewCanvasProps {@@ -221,17 +224,18 @@ export function PreviewCanvas(props: PreviewCanvasProps) {// clip the playhead is currently inside, the same lookup VirtualPreview// itself uses to map playback position back to a clip. `undefined` (no// crop stored) normalises to the identity region.+ const previewInserts = props.insertRanges ?? EMPTY_INSERT_RANGES;const activeClip = useMemo(- () => locateVirtualPosition(props.clips, props.currentTimeSec)?.clip ?? null,- [props.clips, props.currentTimeSec],+ () => locateVirtualPosition(props.clips, props.currentTimeSec, previewInserts)?.clip ?? null,+ [props.clips, props.currentTimeSec, previewInserts],);const cropRegion: CropRegion = activeClip?.cropRegion ?? DEFAULT_CROP_REGION;// P4 — the layout preset is global (one panel for the whole timeline) but the camera// is per clip, so the layout has to be resolved against the clip under the playhead.const activeCameraTrack = useMemo(- () => resolveActiveCameraTrack(assets, props.clips, props.currentTimeSec),- [assets, props.clips, props.currentTimeSec],+ () => resolveActiveCameraTrack(assets, props.clips, props.currentTimeSec, previewInserts),+ [assets, props.clips, props.currentTimeSec, previewInserts],);const activeClipHasCamera = Boolean(activeCameraTrack?.visible && activeCameraTrack.sourcePath);diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex 4e1e395c0..6892bdda7 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -51,6 +51,7 @@ import type {AxcutAsset,AxcutAudioTrack,AxcutClip,+ AxcutInsertRange,AxcutTranscript,AxcutTrimRange,AxcutWord,@@ -111,6 +112,9 @@ import styles from "./NewEditorShell.module.css";import { useTranscriptionLabel } from "./TranscriptionStatus";import { transcriptionBusyLabel } from "./transcriptionBusyLabel";+/** Stable identity, so the memos below are not invalidated every render by a fresh `[]`. */+const EMPTY_INSERT_RANGES: readonly AxcutInsertRange[] = [];+interface PaneProps {title: string;icon: ReactNode;@@ -884,7 +888,11 @@ export function TranscriptPane({// From the RECORDING clips and the whole trim set, never from `placements`: the// programme is one thing, and the voiceover lane is asking whether the film still// contains a moment — not whether some trim happens to name an audio fragment.- const removed = useMemo(() => removedRawSpans(clips, trimRanges), [clips, trimRanges]);+ const insertRanges = document?.timeline.insertRanges ?? EMPTY_INSERT_RANGES;+ const removed = useMemo(+ () => removedRawSpans(clips, trimRanges, insertRanges),+ [clips, trimRanges, insertRanges],+ );// The take's placements are fed the cuts AND its own insertions, so a word after a pause// is struck through — and highlighted — at the moment it is actually heard (issue #560).const insertsFor = useCallback(diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsxindex a68d759d3..cefbc3082 100644--- a/src/components/ai-edition/VirtualPreview.tsx+++ b/src/components/ai-edition/VirtualPreview.tsx@@ -615,12 +615,15 @@ export function VirtualPreview({);const takePiecesRef = useRef<Map<string, TakePiece[]>>(new Map());const takeHeadsRef = useRef<Map<string, string>>(new Map());- const removedRef = useRef(removedRawSpans(clips, trimRanges));- removedRef.current = useMemo(() => removedRawSpans(clips, trimRanges), [clips, trimRanges]);+ const removedRef = useRef(removedRawSpans(clips, trimRanges, insertRanges));+ removedRef.current = useMemo(+ () => removedRawSpans(clips, trimRanges, insertRanges),+ [clips, trimRanges, insertRanges],+ );const takeWalks = useMemo(() => {const pieces = new Map<string, TakePiece[]>();const heads = new Map<string, string>();- const removed = removedRawSpans(clips, trimRanges);+ const removed = removedRawSpans(clips, trimRanges, insertRanges);for (const pill of collapseTracksToPills(audioTracks)) {if (pill.kind !== "voiceover" || pill.loop) continue;const groupId = trackGroupId(pill);@@ -916,6 +919,7 @@ export function VirtualPreview({activeSourceId,v.currentTime,activeClipIdRef.current ?? undefined,+ insertRangesRef.current,);if (nextKeptSegment) {// `findRawClipForSegment` is the ONE definition of the segment-id@@ -926,7 +930,11 @@ export function VirtualPreview({if (rawClip) {activeClipIdRef.current = rawClip.id;}- const rawTargetTime = getRawVirtualStartTime(nextKeptSegment, clipsRef.current);+ const rawTargetTime = getRawVirtualStartTime(+ nextKeptSegment,+ clipsRef.current,+ insertRangesRef.current,+ );seekToVirtualTimeRef.current?.(rawTargetTime, true);return;}@@ -997,6 +1005,7 @@ export function VirtualPreview({activeSourceId,0.05,activeClipIdRef.current ?? undefined,+ insertRangesRef.current,);if (!position) {// ponytail: fall back to timeline order so cross-asset / reordereddiff --git a/src/components/ai-edition/WebcamOverlay.tsx b/src/components/ai-edition/WebcamOverlay.tsxindex d9b256149..9a9dad3dd 100644--- a/src/components/ai-edition/WebcamOverlay.tsx+++ b/src/components/ai-edition/WebcamOverlay.tsx@@ -17,7 +17,7 @@import { useEffect, useMemo, useRef, useState } from "react";import { toFileUrl } from "@/components/video-editor/projectPersistence";import type { WebcamLayoutPreset, WebcamMaskShape } from "@/components/video-editor/types";-import type { AxcutClip } from "@/lib/ai-edition/schema";+import type { AxcutClip, AxcutInsertRange } from "@/lib/ai-edition/schema";import { useProjectStore } from "@/lib/ai-edition/store/projectStore";import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";import { resolveActiveCameraTrack } from "@/lib/ai-edition/timeline/camera";@@ -31,8 +31,14 @@ import { getCssClipPath } from "@/lib/webcamMaskShapes";import { setWebcamNativeSize } from "@/native/webcamSizeCache";import styles from "./NewEditorShell.module.css";+/** Stable identity, so the memos are not invalidated every render by a fresh `[]`. */+const EMPTY_INSERT_RANGES: readonly AxcutInsertRange[] = [];+interface WebcamOverlayProps {clips: AxcutClip[];+ /** The insertions those clips carry — the camera follows the clip under the playhead,+ * and which clip that is cannot be answered without them (issue #560). */+ insertRanges?: readonly AxcutInsertRange[];currentTimeSec: number;onTimeChange: (sec: number) => void;isPlaying: boolean;@@ -61,14 +67,15 @@ export function WebcamOverlay(props: WebcamOverlayProps) {// Fallback (pre-clockRef / first paint) position from props, used only for// the initial correction on loadedmetadata before the rAF loop below has// had a chance to run.+ const overlayInserts = props.insertRanges ?? EMPTY_INSERT_RANGES;const position = useMemo(- () => locateVirtualPosition(props.clips, props.currentTimeSec),- [props.clips, props.currentTimeSec],+ () => locateVirtualPosition(props.clips, props.currentTimeSec, overlayInserts),+ [props.clips, props.currentTimeSec, overlayInserts],);const cameraTrack = useMemo(- () => resolveActiveCameraTrack(assets ?? [], props.clips, props.currentTimeSec),- [assets, props.clips, props.currentTimeSec],+ () => resolveActiveCameraTrack(assets ?? [], props.clips, props.currentTimeSec, overlayInserts),+ [assets, props.clips, props.currentTimeSec, overlayInserts],);const cameraTime = useMemo(() => {@@ -81,6 +88,8 @@ export function WebcamOverlay(props: WebcamOverlayProps) {// re-creating the loop on every document mutation.const clipsRef = useRef(props.clips);clipsRef.current = props.clips;+ const insertsRef = useRef(overlayInserts);+ insertsRef.current = overlayInserts;const assetsRef = useRef(assets);assetsRef.current = assets;@@ -97,11 +106,12 @@ export function WebcamOverlay(props: WebcamOverlayProps) {raf = window.requestAnimationFrame(tick);const clock = clockRef.current;const clipsNow = clipsRef.current;- const positionNow = locateVirtualPosition(clipsNow, clock.virtualTimeSec);+ const positionNow = locateVirtualPosition(clipsNow, clock.virtualTimeSec, insertsRef.current);const trackNow = resolveActiveCameraTrack(assetsRef.current ?? [],clipsNow,clock.virtualTimeSec,+ insertsRef.current,);const target = resolveCameraSyncTarget(clock,diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex ef487f931..b4db553ec 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -1095,7 +1095,7 @@ export function V4Timeline({// so a notch cannot appear where the voice does not actually stop.const takePieces = useMemo(() => {const clipAssetIds = new Set(clips.map((c) => c.assetId));- const removed = removedRawSpans(clips, tl.trimRanges);+ const removed = removedRawSpans(clips, tl.trimRanges, tl.insertRanges ?? []);const out = new Map<string, TakePiece[]>();for (const pill of audioPills) {if (pill.kind !== "voiceover" || pill.loop) continue;diff --git a/src/lib/ai-edition/captions/cues.ts b/src/lib/ai-edition/captions/cues.tsindex 76472112f..3eeaf08e8 100644--- a/src/lib/ai-edition/captions/cues.ts+++ b/src/lib/ai-edition/captions/cues.ts@@ -251,7 +251,11 @@ export function deriveCaptionCues(// `?? []` for the same reason `insertRanges` has one: the key is additive, so a// document written before it — or hand-built, never through the schema — has none.document.audioTracks ?? [],- removedRawSpans(document.timeline.clips, document.timeline.trimRanges),+ removedRawSpans(+ document.timeline.clips,+ document.timeline.trimRanges,+ document.timeline.insertRanges ?? [],+ ),(groupId) => takeInserts(document, groupId),);if (placements.length === 0) return [];diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.tsindex 012d45947..08d63460d 100644--- a/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts+++ b/src/lib/ai-edition/timeline/aggregated-transcript.lanes.test.ts@@ -215,7 +215,7 @@ describe("one programme, two lanes", () => {const VO = track({ id: "vo_1", startMs: 0, endMs: 12000, offsetMs: 0, durationSec: 12 });function lanes(trims: (typeof TRIM)[]) {- const removed = removedRawSpans(CLIPS_2, trims);+ const removed = removedRawSpans(CLIPS_2, trims, []);const transcripts = [secondsTranscript("asset_rec", 12), secondsTranscript("asset_vo", 12)];const build = (lane: "recording" | "voiceover") =>buildAggregatedSections(@@ -256,7 +256,7 @@ describe("one programme, two lanes", () => {it("removes a word over an inter-clip gap, with nothing to restore", () => {const gapped = [CLIPS_2[0], { ...CLIPS_2[1], timelineStartSec: 8, timelineEndSec: 14 }];- const removed = removedRawSpans(gapped, []);+ const removed = removedRawSpans(gapped, [], []);const sections = buildAggregatedSections(voiceoverPlacements([track({ id: "vo_1", startMs: 0, endMs: 14000, durationSec: 14 })]),// biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise@@ -280,7 +280,7 @@ describe("one programme, two lanes", () => {// biome-ignore lint/suspicious/noExplicitAny: fixture, not a schema exercise[secondsTranscript("asset_vo", 20)] as any,[],- removedRawSpans(CLIPS_2, []),+ removedRawSpans(CLIPS_2, [], []),);const w15 = sections.flatMap((s) => s.words).find((w) => w.word.id === "w15");expect(w15?.kept).toBe(true);diff --git a/src/lib/ai-edition/timeline/aggregated-transcript.test.ts b/src/lib/ai-edition/timeline/aggregated-transcript.test.tsindex 1a62d7e4c..987b5a3a5 100644--- a/src/lib/ai-edition/timeline/aggregated-transcript.test.ts+++ b/src/lib/ai-edition/timeline/aggregated-transcript.test.ts@@ -83,7 +83,7 @@ describe("buildClipSection", () => {clip,transcript,makeAsset(),- removedRawSpans([clip], [trim]),+ removedRawSpans([clip], [trim], []),);expect(section.words.map((cw) => cw.kept)).toEqual([true, false, false, false, true]);expect(section.words.map((cw) => cw.trimIds)).toEqual([@@ -117,7 +117,12 @@ describe("buildClipSection", () => {makeTrim({ id: "trim_b", startSec: 3, endSec: 4 }),];- const section = buildClipSection(clip, transcript, makeAsset(), removedRawSpans([clip], trims));+ const section = buildClipSection(+ clip,+ transcript,+ makeAsset(),+ removedRawSpans([clip], trims, []),+ );expect(section.trimRuns).toHaveLength(2);expect(section.trimRuns[0]).toMatchObject({trimIds: ["trim_a"],@@ -157,7 +162,7 @@ describe("buildClipSection", () => {clips,[makeTranscript(words())],[makeAsset()],- removedRawSpans(clips, [trim]),+ removedRawSpans(clips, [trim], []),);expect(sections[0].words.map((cw) => cw.kept)).toEqual([true, true, true]);@@ -176,7 +181,7 @@ describe("buildClipSection", () => {clips,[makeTranscript(words())],[makeAsset()],- removedRawSpans(clips, [trim]),+ removedRawSpans(clips, [trim], []),);expect(sections[0].trimRuns).toHaveLength(1);expect(sections[1].trimRuns).toHaveLength(1);@@ -195,7 +200,7 @@ describe("buildClipSection", () => {clip,transcript,makeAsset(),- removedRawSpans([clip], [trim]),+ removedRawSpans([clip], [trim], []),);// Trailing gap 2s→3s is a silence — the different-asset trim doesn't// cover any of the three entries, so all stay kept.@@ -278,7 +283,7 @@ describe("silence gaps", () => {clip,transcript,makeAsset(),- removedRawSpans([clip], [trim]),+ removedRawSpans([clip], [trim], []),);const silence = section.words.find((cw) => isSilenceWord(cw.word));expect(silence?.kept).toBe(false);diff --git a/src/lib/ai-edition/timeline/camera.test.ts b/src/lib/ai-edition/timeline/camera.test.tsindex 1f7fea91b..e1caa03a5 100644--- a/src/lib/ai-edition/timeline/camera.test.ts+++ b/src/lib/ai-edition/timeline/camera.test.ts@@ -56,6 +56,7 @@ describe("resolveActiveCameraTrack", () => {[assetWithCamera, assetWithoutCamera],[clipWithCamera, clipWithoutCamera],2,+ [],);expect(track?.sourcePath).toBe("/cam-1.mp4");});@@ -65,17 +66,18 @@ describe("resolveActiveCameraTrack", () => {[assetWithCamera, assetWithoutCamera],[clipWithCamera, clipWithoutCamera],7,+ [],);expect(track).toBeNull();});it("returns null when there are no clips", () => {- expect(resolveActiveCameraTrack([assetWithCamera], [], 0)).toBeNull();+ expect(resolveActiveCameraTrack([assetWithCamera], [], 0, [])).toBeNull();});it("returns null when the active clip references an unknown asset", () => {const orphanClip: AxcutClip = { ...clipWithCamera, assetId: "missing" };- expect(resolveActiveCameraTrack([assetWithCamera], [orphanClip], 2)).toBeNull();+ expect(resolveActiveCameraTrack([assetWithCamera], [orphanClip], 2, [])).toBeNull();});});diff --git a/src/lib/ai-edition/timeline/camera.ts b/src/lib/ai-edition/timeline/camera.tsindex 4fc576952..0f11ed0ce 100644--- a/src/lib/ai-edition/timeline/camera.ts+++ b/src/lib/ai-edition/timeline/camera.ts@@ -4,15 +4,18 @@// timeline, and whether the timeline has ANY camera at all — used to gate// camera-only preview chrome and settings controls.-import type { AxcutAsset, AxcutCameraTrack, AxcutClip } from "../schema";+import type { AxcutAsset, AxcutCameraTrack, AxcutClip, AxcutInsertRange } from "../schema";import { locateVirtualPosition } from "./virtual-preview";export function resolveActiveCameraTrack(assets: AxcutAsset[],clips: AxcutClip[],currentTimeSec: number,+ /** REQUIRED: a clip carrying insertions is longer than its source window, so which clip+ * a timeline second falls on cannot be answered without them (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): AxcutCameraTrack | null {- const position = locateVirtualPosition(clips, currentTimeSec);+ const position = locateVirtualPosition(clips, currentTimeSec, insertRanges);if (!position) return null;const activeAsset = assets.find((a) => a.id === position.clip.assetId);return activeAsset?.cameraTrack ?? null;diff --git a/src/lib/ai-edition/timeline/cursor-track.ts b/src/lib/ai-edition/timeline/cursor-track.tsindex aec4324a4..f190828d6 100644--- a/src/lib/ai-edition/timeline/cursor-track.ts+++ b/src/lib/ai-edition/timeline/cursor-track.ts@@ -16,7 +16,7 @@// sample, nothing is summarised, and every pointer-shape change survives the// reduction because a shape change is an observed event, not a verdict about it.-import type { AxcutClip, AxcutTrimRange } from "../schema";+import type { AxcutClip, AxcutInsertRange, AxcutTrimRange } from "../schema";import { locateSourcePosition } from "./virtual-preview";/**@@ -158,6 +158,9 @@ export interface CursorTrackOptions {durationSec: number;clips: AxcutClip[];trimRanges?: AxcutTrimRange[];+ /** The insertions those clips carry: a clip carrying one is longer than its source+ * window, so a capture timestamp's place on the timeline moves with them (issue #560). */+ insertRanges?: readonly AxcutInsertRange[];hz?: number;maxPoints?: number;/** Movement threshold in frame fractions; see DEFAULT_TRACK_EPSILON. */@@ -169,6 +172,7 @@ export interface CursorTrackOptions {export function buildCursorTrack(options: CursorTrackOptions): CursorTrack {const { assetId, samples, durationSec, clips } = options;const trimRanges = options.trimRanges ?? [];+ const insertRanges = options.insertRanges ?? [];const maxPoints = options.maxPoints ?? DEFAULT_MAX_TRACK_POINTS;const ceilingMs = Math.max(0, durationSec) * 1000 || Number.POSITIVE_INFINITY;@@ -294,7 +298,7 @@ export function buildCursorTrack(options: CursorTrackOptions): CursorTrack {// not told twice.const shifted = keep.some((s) => {const atSec = s.timeMs / 1000;- const position = locateSourcePosition(clips, atSec, assetId);+ const position = locateSourcePosition(clips, atSec, assetId, 0.05, undefined, insertRanges);return !position || Math.abs(position.virtualTimeSec - atSec) > 0.005;});@@ -303,7 +307,7 @@ export function buildCursorTrack(options: CursorTrackOptions): CursorTrack {// `locateSourcePosition` is the existing source→virtual mapping, exact here// because trims do NOT compact the document's virtual axis — a trim is a hole// in playback, not a shortening of the ruler (see timeline/trim-mapping.ts).- const position = locateSourcePosition(clips, atSec, assetId);+ const position = locateSourcePosition(clips, atSec, assetId, 0.05, undefined, insertRanges);const point: CursorTrackPoint = {atSec: round2(atSec),cx: round3(s.cx),diff --git a/src/lib/ai-edition/timeline/programme-time.test.ts b/src/lib/ai-edition/timeline/programme-time.test.tsindex 7b2b35cca..e302703dd 100644--- a/src/lib/ai-edition/timeline/programme-time.test.ts+++ b/src/lib/ai-edition/timeline/programme-time.test.ts@@ -114,7 +114,7 @@ describe("keptRawSpans agrees with playback", () => {(sum, seg) => sum + ((seg.sourceEndSec ?? seg.sourceStartSec) - seg.sourceStartSec),0,);- const kept = keptRawSpans(clips, trims);+ const kept = keptRawSpans(clips, trims, []);expect(total(kept), `seed ${seed} total`).toBeCloseTo(played, 6);// The sum alone is blind to ORDER, and order is the whole reason this walk was@@ -153,7 +153,7 @@ describe("keptRawSpans agrees with playback", () => {timelineEndSec: 6,}),];- expect(keptRawSpans(clips, []).map((s) => s.startSec)).toEqual([0, 6]);+ expect(keptRawSpans(clips, [], []).map((s) => s.startSec)).toEqual([0, 6]);});it("leaves the projection identical to what it produced before the lift", () => {@@ -178,8 +178,8 @@ describe("removedRawSpans", () => {trim({ id: "t1", clipId: "c1", startSec: 2, endSec: 4 }),trim({ id: "t2", clipId: "c2", startSec: 15, endSec: 16 }),];- const kept = [...keptRawSpans(clips, trims)].sort((a, b) => a.startSec - b.startSec);- const removed = removedRawSpans(clips, trims);+ const kept = [...keptRawSpans(clips, trims, [])].sort((a, b) => a.startSec - b.startSec);+ const removed = removedRawSpans(clips, trims, []);const all = [...kept, ...removed].sort((a, b) => a.startSec - b.startSec);let cursor = 0;@@ -201,7 +201,7 @@ describe("removedRawSpans", () => {timelineEndSec: 23,}),];- const gap = removedRawSpans(clips, []).find((s) => s.startSec === 10);+ const gap = removedRawSpans(clips, [], []).find((s) => s.startSec === 10);expect(gap).toMatchObject({ startSec: 10, endSec: 13 });// No trim took it, so the pane must not offer a restore.expect(gap?.trimIds).toEqual([]);@@ -210,7 +210,7 @@ describe("removedRawSpans", () => {it("removes a trimmed tail of the last clip but never the time past it", () => {const clips = [twoClips()[0]];const trims = [trim({ id: "t1", clipId: "c1", startSec: 8, endSec: 10 })];- const removed = removedRawSpans(clips, trims);+ const removed = removedRawSpans(clips, trims, []);expect(removed).toEqual([{ startSec: 8, endSec: 10, trimIds: ["t1"] }]);// Raw 12 is unfilmed, not removed — the distinction a voiceover overhanging the// programme depends on.@@ -225,7 +225,7 @@ describe("removedRawSpans", () => {// playback walk cuts on overlap, per clip, and this must match it.const clips = twoClips();const trims = [trim({ id: "t1", startSec: 5, endSec: 15 })]; // no clipId- const removed = removedRawSpans(clips, trims);+ const removed = removedRawSpans(clips, trims, []);expect(removalAt(removed, 6)).toMatchObject({ trimIds: ["t1"] }); // inside c1expect(removalAt(removed, 12)).toMatchObject({ trimIds: ["t1"] }); // inside c2expect(removalAt(removed, 2)).toBeNull();@@ -240,22 +240,24 @@ describe("removedRawSpans", () => {];// `subtractInterval` merges the two into one hole; both ids come with it, so// restoring from the pane can drop the whole pill.- expect(removedRawSpans(clips, trims)).toEqual([+ expect(removedRawSpans(clips, trims, [])).toEqual([{ startSec: 2, endSec: 7, trimIds: ["t1", "t2"] },]);});it("returns nothing for a document with no clips", () => {- expect(removedRawSpans([], [trim({ id: "t1" })])).toEqual([]);+ expect(removedRawSpans([], [trim({ id: "t1" })], [])).toEqual([]);});});describe("subtractRemoved", () => {it("splits a span that crosses a cut into the pieces that survive", () => {const clips = twoClips();- const removed = removedRawSpans(clips, [- trim({ id: "t1", clipId: "c1", startSec: 3, endSec: 5 }),- ]);+ const removed = removedRawSpans(+ clips,+ [trim({ id: "t1", clipId: "c1", startSec: 3, endSec: 5 })],+ [],+ );// A voiceover from raw 1 to raw 8 plays as two pieces, not as one take cut short.expect(subtractRemoved(1, 8, removed)).toEqual([{ startSec: 1, endSec: 3 },@@ -265,9 +267,11 @@ describe("subtractRemoved", () => {it("yields nothing for a span buried inside a cut, and the whole span when untouched", () => {const clips = twoClips();- const removed = removedRawSpans(clips, [- trim({ id: "t1", clipId: "c1", startSec: 3, endSec: 8 }),- ]);+ const removed = removedRawSpans(+ clips,+ [trim({ id: "t1", clipId: "c1", startSec: 3, endSec: 8 })],+ [],+ );expect(subtractRemoved(4, 6, removed)).toEqual([]);expect(subtractRemoved(10, 14, removed)).toEqual([{ startSec: 10, endSec: 14 }]);// Past the programme is not removed, so an overhanging take keeps its tail.@@ -343,3 +347,61 @@ describe("projectRawTimelineSecToPlayback across an insertion", () => {expect(projectRawTimelineSecToPlayback(clips, [], 8, inserted, speed)).toBeCloseTo(4, 6);});});++// ─── The hole an insertion is not ────────────────────────────────────────────+// `clipRawExtent` measured a clip by its SOURCE window, so a clip carrying insertions+// ended short by exactly the inserted time — and `removedRawSpans`, walking clip to clip,+// reported the difference as a gap nothing had removed. Everything that cuts on removed+// spans then cut there: a voiceover crossing it went silent for the insertion's length, in+// the preview and in the exported mix, and its words were struck through in the transcript+// pane. The user heard the voice drop out exactly where they added a word (issue #560).++describe("an insertion is not a hole in the programme", () => {+ const inserted: AxcutInsertRange[] = [+ {+ id: "i1",+ assetId: "a1",+ atSec: 5,+ durationSec: 1,+ wordId: "w1",+ reason: "",+ origin: "user",+ },+ ];+ const clips = [+ clip({+ id: "c1",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 11,+ }),+ clip({+ id: "c2",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 11,+ timelineEndSec: 21,+ }),+ ];++ it("reports nothing removed when nothing was trimmed", () => {+ expect(removedRawSpans(clips, [], inserted)).toEqual([]);+ });++ it("covers the insertion's own seconds as kept programme", () => {+ const spans = keptRawSpans(clips, [], inserted);+ const covers = (sec: number) => spans.some((s) => sec >= s.startSec && sec < s.endSec);+ // 5.5 is inside the inserted media, 10.5 is the first clip's last second.+ expect(covers(5.5)).toBe(true);+ expect(covers(10.5)).toBe(true);+ });++ it("still reports a real gap between two clips", () => {+ const apart = [clips[0], clip({ ...clips[1], timelineStartSec: 13, timelineEndSec: 23 })];+ const removed = removedRawSpans(apart, [], inserted);+ expect(removed).toHaveLength(1);+ expect(removed[0].startSec).toBeCloseTo(11, 6);+ expect(removed[0].endSec).toBeCloseTo(13, 6);+ });+});diff --git a/src/lib/ai-edition/timeline/programme-time.ts b/src/lib/ai-edition/timeline/programme-time.tsindex f2b7cb3ec..d9bfd77a7 100644--- a/src/lib/ai-edition/timeline/programme-time.ts+++ b/src/lib/ai-edition/timeline/programme-time.ts@@ -19,7 +19,7 @@// derived READING of those rows, computed on demand and never written back.import type { AxcutClip, AxcutInsertRange, AxcutTrimRange } from "../schema";-import { sourceToTimelineSec } from "./inserted-time";+import { assignInsertsToClips, sourceToTimelineSec } from "./inserted-time";import { type Interval, subtractInterval } from "./intervals";import { trimAppliesToClip } from "./trim-mapping";@@ -48,14 +48,22 @@ export interface RemovedRawSpan extends RawSpan {* source length to measure, and falls back to the ruler geometry it was given — matching* the pass-through branch `resolvePlaybackSegments` takes for the same clips.*/-function clipRawExtent(clip: AxcutClip): RawSpan {+/** A clip's whole stretch of timeline — its source window PLUS the media inserted inside it.+ *+ * Computed, not read off `timelineEndSec`: derived the same way `reflowClipsForInserts`+ * writes it, so a clip whose stored geometry is stale or half-written cannot make this lie.+ * Leaving the insertions out was its own bug — the extent then ended short by exactly the+ * inserted time, and `removedRawSpans` reported a phantom hole at the tail of every clip+ * carrying one, which the audio paths cut as if a trim had taken it. */+function clipRawExtent(clip: AxcutClip, ownInserts: readonly AxcutInsertRange[]): RawSpan {const sourceEnd = clip.sourceEndSec ?? clip.sourceStartSec;if (sourceEnd <= clip.sourceStartSec) {return { startSec: clip.timelineStartSec, endSec: clip.timelineEndSec };}+ const owed = ownInserts.reduce((sum, insert) => sum + insert.durationSec, 0);return {startSec: clip.timelineStartSec,- endSec: clip.timelineStartSec + (sourceEnd - clip.sourceStartSec),+ endSec: clip.timelineStartSec + (sourceEnd - clip.sourceStartSec) + owed,};}@@ -102,15 +110,19 @@ function keptSourceIntervals(clip: AxcutClip, trimRanges: AxcutTrimRange[]): Intexport function keptRawSpans(clips: AxcutClip[],trimRanges: AxcutTrimRange[],- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): RawSpan[] {const ordered = [...clips].sort((a, b) => a.timelineStartSec - b.timelineStartSec);+ const owners = assignInsertsToClips(ordered, insertRanges);const spans: RawSpan[] = [];for (const clip of ordered) {const sourceEnd = clip.sourceEndSec ?? clip.sourceStartSec;if (sourceEnd <= clip.sourceStartSec) {// Duration not probed yet — the whole raw clip passes through unnarrowed.- const extent = clipRawExtent(clip);+ const extent = clipRawExtent(clip, owners.get(clip.id) ?? []);if (extent.endSec > extent.startSec) spans.push(extent);continue;}@@ -140,16 +152,20 @@ export function keptRawSpans(export function removedRawSpans(clips: AxcutClip[],trimRanges: AxcutTrimRange[],- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): RemovedRawSpan[] {const ordered = [...clips].sort((a, b) => a.timelineStartSec - b.timelineStartSec);if (ordered.length === 0) return [];+ const owners = assignInsertsToClips(ordered, insertRanges);const removed: RemovedRawSpan[] = [];let cursor = 0; // raw end of the programme walked so farfor (const clip of ordered) {- const extent = clipRawExtent(clip);+ const extent = clipRawExtent(clip, owners.get(clip.id) ?? []);// The unfilmed stretch before this clip. `max` rather than a bare subtraction so// two clips overlapping on the ruler contribute no negative gap.if (extent.startSec > cursor) {diff --git a/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts b/src/lib/ai-edition/timeline/sharedMediaTrim.test.tsindex 5bbe7ac44..b132308ef 100644--- a/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts+++ b/src/lib/ai-edition/timeline/sharedMediaTrim.test.ts@@ -74,7 +74,7 @@ describe("repro: trim on clip 2 of two clips sharing one media", () => {next.timeline.clips,next.transcripts,next.assets,- removedRawSpans(next.timeline.clips, next.timeline.trimRanges),+ removedRawSpans(next.timeline.clips, next.timeline.trimRanges, []),);expect(sections[0].trimRuns).toHaveLength(0);expect(sections[1].trimRuns).toHaveLength(1);diff --git a/src/lib/ai-edition/timeline/take-programme.test.ts b/src/lib/ai-edition/timeline/take-programme.test.tsindex 37c7d595a..7cf3cce0c 100644--- a/src/lib/ai-edition/timeline/take-programme.test.ts+++ b/src/lib/ai-edition/timeline/take-programme.test.ts@@ -64,7 +64,7 @@ describe("takeProgramme", () => {[trim(8, 12)],[trim(2, 3), trim(6, 7, "t2")],]) {- const removed = removedRawSpans(CLIPS, cuts);+ const removed = removedRawSpans(CLIPS, cuts, []);const played = takeProgramme(TAKE, removed, []).filter((p) => p.kind === "play").map((p) => [p.rawStartSec, p.rawEndSec]);@@ -107,7 +107,7 @@ describe("takeProgramme", () => {});it("gives nothing to an insertion a cut swallowed", () => {- const removed = removedRawSpans(CLIPS, [trim(3, 6)]);+ const removed = removedRawSpans(CLIPS, [trim(3, 6)], []);const withIt = takeProgramme(TAKE, removed, [ins(4, 1)]);const without = takeProgramme(TAKE, removed, []);// The moment it holds is not in the film any more, so it buys no time.@@ -116,7 +116,7 @@ describe("takeProgramme", () => {});it("keeps an insertion on a cut's far edge, which is what follows the cut", () => {- const removed = removedRawSpans(CLIPS, [trim(3, 6)]);+ const removed = removedRawSpans(CLIPS, [trim(3, 6)], []);const pieces = takeProgramme(TAKE, removed, [ins(6, 1)]);expect(pieces.map((p) => p.kind)).toEqual(["play", "removed", "hold", "play"]);});@@ -159,7 +159,7 @@ describe("rawSpanForOutDuration", () => {});describe("takePlaybackAt", () => {- const pieces = takeProgramme(TAKE, removedRawSpans(CLIPS, [trim(7, 8)]), [ins(4, 1)]);+ const pieces = takeProgramme(TAKE, removedRawSpans(CLIPS, [trim(7, 8)], []), [ins(4, 1)]);it("plays the file where the file plays", () => {expect(takePlaybackAt(pieces, 2)).toMatchObject({ targetTimeSec: 2, shouldPlay: true });@@ -189,7 +189,7 @@ describe("takePlaybackAt", () => {// play are the entries the export emits, piece for piece.describe("preview and export agree over a take with a cut and a pause", () => {- const removed = removedRawSpans(CLIPS, [trim(7, 8)]);+ const removed = removedRawSpans(CLIPS, [trim(7, 8)], []);const pieces = takeProgramme(TAKE, removed, [ins(4, 1)]);it("plays exactly the play pieces, and nothing between them", () => {@@ -263,7 +263,7 @@ describe("the pieces a pill draws", () => {});it("covers the pill end to end, with no overlap and no hole", () => {- const pieces = takeProgramme(TAKE, removedRawSpans(CLIPS, [trim(7, 8)]), [ins(4, 1)]);+ const pieces = takeProgramme(TAKE, removedRawSpans(CLIPS, [trim(7, 8)], []), [ins(4, 1)]);let cursor = TAKE.startMs / 1000;for (const piece of pieces) {expect(piece.rawStartSec).toBeCloseTo(cursor, 6);diff --git a/src/lib/ai-edition/timeline/timelineMap.test.ts b/src/lib/ai-edition/timeline/timelineMap.test.tsindex b06ac8fb9..608350a49 100644--- a/src/lib/ai-edition/timeline/timelineMap.test.ts+++ b/src/lib/ai-edition/timeline/timelineMap.test.ts@@ -48,7 +48,7 @@ const region = (id: string, startSec: number, endSec: number, payload?: string):describe("projectRegionsToSource", () => {it("passes a region through unchanged (no clipIndex) when there are no segments", () => {- const out = projectRegionsToSource([region("r", 1.5, 4.25)], [], [], () => "x");+ const out = projectRegionsToSource([region("r", 1.5, 4.25)], [], [], () => "x", []);expect(out).toEqual([{ id: "r", startMs: 1500, endMs: 4250 }]);});@@ -60,7 +60,7 @@ describe("projectRegionsToSource", () => {sourceEndSec: 10,timelineEndSec: 10,});- const out = projectRegionsToSource([region("r", 3, 5)], [c], [c], () => "x");+ const out = projectRegionsToSource([region("r", 3, 5)], [c], [c], () => "x", []);expect(out).toEqual([{ id: "r", startMs: 3000, endMs: 5000, clipIndex: 0 }]);});@@ -75,7 +75,7 @@ describe("projectRegionsToSource", () => {timelineEndSec: 10,});const segments = resolvePlaybackSegments([c], [trim("a", 2, 4)]);- const out = projectRegionsToSource([region("r", 6, 8)], segments, [c], () => "x");+ const out = projectRegionsToSource([region("r", 6, 8)], segments, [c], () => "x", []);expect(out).toEqual([{ id: "r", startMs: 6000, endMs: 8000, clipIndex: 1 }]);});@@ -96,7 +96,13 @@ describe("projectRegionsToSource", () => {timelineStartSec: 5,timelineEndSec: 10,});- const out = projectRegionsToSource([region("r", 3, 7, "keep")], [c1, c2], [c1, c2], () => "r2");+ const out = projectRegionsToSource(+ [region("r", 3, 7, "keep")],+ [c1, c2],+ [c1, c2],+ () => "r2",+ [],+ );expect(out).toEqual([{ id: "r", startMs: 103000, endMs: 105000, clipIndex: 0, payload: "keep" },{ id: "r2", startMs: 200000, endMs: 202000, clipIndex: 1, payload: "keep" },@@ -114,7 +120,7 @@ describe("projectRegionsToSource", () => {timelineEndSec: 10,});const segments = resolvePlaybackSegments([c], [trim("a", 4, 6)]);- const out = projectRegionsToSource([region("r", 3, 8)], segments, [c], () => "r2");+ const out = projectRegionsToSource([region("r", 3, 8)], segments, [c], () => "r2", []);expect(out).toEqual([{ id: "r", startMs: 3000, endMs: 4000, clipIndex: 0 },{ id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1 },@@ -149,7 +155,7 @@ describe("projectRegionsToSource", () => {const segments = resolvePlaybackSegments([c1, c2], [trim("a", 2, 8)]);// segments: c1[0,2] (0), c1[8,10] (1), c2[0,10] (2).const anchored = { ...region("r", 3, 5), clipId: "c1", sourceStartSec: 3, sourceEndSec: 5 };- expect(projectRegionsToSource([anchored], segments, [c1, c2], () => "x")).toEqual([+ expect(projectRegionsToSource([anchored], segments, [c1, c2], () => "x", [])).toEqual([{ ...anchored, startMs: 3000, endMs: 5000, clipIndex: 0, underTrim: true },]);});@@ -175,7 +181,7 @@ describe("projectRegionsToSource", () => {});const segments = resolvePlaybackSegments([c1, c2], [trim("a", 0, 10)]);const anchored = { ...region("r", 3, 5), clipId: "c1", sourceStartSec: 3, sourceEndSec: 5 };- expect(projectRegionsToSource([anchored], segments, [c1, c2], () => "x")).toEqual([]);+ expect(projectRegionsToSource([anchored], segments, [c1, c2], () => "x", [])).toEqual([]);});it("keeps an unanchored region a trim removes entirely, mapped through its raw clip", () => {@@ -191,7 +197,7 @@ describe("projectRegionsToSource", () => {timelineEndSec: 10,});const segments = resolvePlaybackSegments([c], [trim("a", 4, 6)]);- expect(projectRegionsToSource([region("r", 4.5, 5.5)], segments, [c], () => "x")).toEqual([+ expect(projectRegionsToSource([region("r", 4.5, 5.5)], segments, [c], () => "x", [])).toEqual([{ id: "r", startMs: 4500, endMs: 5500, clipIndex: 0, underTrim: true },]);});@@ -208,7 +214,7 @@ describe("projectRegionsToSource", () => {});const segments = resolvePlaybackSegments([c], [trim("a", 0, 3)]);const anchored = { ...region("r", 1, 2), clipId: "c1", sourceStartSec: 1, sourceEndSec: 2 };- expect(projectRegionsToSource([anchored], segments, [c], () => "x")).toEqual([+ expect(projectRegionsToSource([anchored], segments, [c], () => "x", [])).toEqual([{ ...anchored, startMs: 1000, endMs: 2000, clipIndex: 0, underTrim: true },]);});@@ -234,9 +240,9 @@ describe("projectRegionsToSource", () => {});const segments = resolvePlaybackSegments([c1, c2], [trim("a", 6, 10)]);const anchored = { ...region("r", 7, 9), clipId: "c1", sourceStartSec: 7, sourceEndSec: 9 };- const [projected] = projectRegionsToSource([anchored], segments, [c1, c2], () => "x");+ const [projected] = projectRegionsToSource([anchored], segments, [c1, c2], () => "x", []);// raw 8 is inside c1's removed tail; the region covering source [7,9] is that same cut.- expect(resolveNativePosition(8, segments, [c1, c2])?.clipIndex).toBe(projected.clipIndex);+ expect(resolveNativePosition(8, segments, [c1, c2], [])?.clipIndex).toBe(projected.clipIndex);});// --- anchored path: the anchor is the SSOT, `startMs`/`endMs` are not consulted ---@@ -258,7 +264,7 @@ describe("projectRegionsToSource", () => {sourceStartSec: 6,sourceEndSec: 8,};- const out = projectRegionsToSource([stale], [c], [c], () => "x");+ const out = projectRegionsToSource([stale], [c], [c], () => "x", []);expect(out).toEqual([{ ...stale, startMs: 6000, endMs: 8000, clipIndex: 0 }]);});@@ -278,7 +284,7 @@ describe("projectRegionsToSource", () => {sourceStartSec: 3,sourceEndSec: 8,};- const out = projectRegionsToSource([anchored], segments, [c], () => "r2");+ const out = projectRegionsToSource([anchored], segments, [c], () => "r2", []);expect(out).toEqual([{ ...anchored, id: "r", startMs: 3000, endMs: 4000, clipIndex: 0 },{ ...anchored, id: "r2", startMs: 6000, endMs: 8000, clipIndex: 1 },@@ -310,7 +316,7 @@ describe("projectRegionsToSource", () => {sourceStartSec: 1,sourceEndSec: 2,};- const out = projectRegionsToSource([anchored], [c1, c2], [c1, c2], () => "x");+ const out = projectRegionsToSource([anchored], [c1, c2], [c1, c2], () => "x", []);expect(out).toEqual([{ ...anchored, startMs: 1000, endMs: 2000, clipIndex: 1 }]);});@@ -325,7 +331,7 @@ describe("projectRegionsToSource", () => {timelineEndSec: 10,});const partial = { ...region("r", 3, 5), clipId: "c1" }; // no source span- const out = projectRegionsToSource([partial], [c], [c], () => "x");+ const out = projectRegionsToSource([partial], [c], [c], () => "x", []);expect(out).toEqual([{ ...partial, startMs: 3000, endMs: 5000, clipIndex: 0 }]);});});@@ -351,12 +357,12 @@ describe("resolveNativePosition", () => {timelineEndSec: 12,}),];- expect(resolveNativePosition(6.5, clips, clips)).toMatchObject({+ expect(resolveNativePosition(6.5, clips, clips, [])).toMatchObject({clip: { id: "c2" },clipIndex: 1,sourceTimeSec: 22.5,});- expect(resolveNativePosition(10, clips, clips)).toMatchObject({+ expect(resolveNativePosition(10, clips, clips, [])).toMatchObject({clip: { id: "c3" },clipIndex: 2,sourceTimeSec: 42,@@ -383,12 +389,12 @@ describe("resolveNativePosition", () => {timelineEndSec: 12,}),];- expect(resolveNativePosition(7.25, clips, clips)).toMatchObject({+ expect(resolveNativePosition(7.25, clips, clips, [])).toMatchObject({clip: { assetId: "asset-b" },clipIndex: 1,sourceTimeSec: 103.25,});- expect(resolveNativePosition(11, clips, clips)).toMatchObject({+ expect(resolveNativePosition(11, clips, clips, [])).toMatchObject({clip: { assetId: "asset-c" },clipIndex: 2,sourceTimeSec: 14,@@ -405,11 +411,11 @@ describe("resolveNativePosition", () => {});const segments = resolvePlaybackSegments([c], [trim("a", 2, 4)]);// raw 1 → source 1 on seg1; raw 6 → source 6 on seg2 (NOT 8).- expect(resolveNativePosition(1, segments, [c])).toMatchObject({+ expect(resolveNativePosition(1, segments, [c], [])).toMatchObject({clipIndex: 0,sourceTimeSec: 1,});- expect(resolveNativePosition(6, segments, [c])).toMatchObject({+ expect(resolveNativePosition(6, segments, [c], [])).toMatchObject({clipIndex: 1,sourceTimeSec: 6,});@@ -430,7 +436,7 @@ describe("resolveNativePosition", () => {// points at, and would incrust any modifier under the cut on someone else's image (#216).// The segment it borrows is the one the cut interrupts (seg1), so a modifier under that// cut — addressed the same way — survives `belongs()`.- expect(resolveNativePosition(3, segments, [c])).toMatchObject({+ expect(resolveNativePosition(3, segments, [c], [])).toMatchObject({clipIndex: 0,sourceTimeSec: 3,});@@ -445,7 +451,7 @@ describe("resolveNativePosition", () => {timelineEndSec: 10,});const segments = resolvePlaybackSegments([c], [trim("a", 0, 3)]);- expect(resolveNativePosition(1, segments, [c])).toMatchObject({+ expect(resolveNativePosition(1, segments, [c], [])).toMatchObject({clipIndex: 0,sourceTimeSec: 1,});@@ -461,11 +467,11 @@ describe("resolveNativePosition", () => {});const segments = resolvePlaybackSegments([c], [trim("a", 2, 4)]);// No raw clip owns raw 99 — nothing to present, so the historical clamp stands.- expect(resolveNativePosition(99, segments, [c])).toMatchObject({ clipIndex: 1 });+ expect(resolveNativePosition(99, segments, [c], [])).toMatchObject({ clipIndex: 1 });});it("returns null when there are no segments", () => {- expect(resolveNativePosition(1, [], [])).toBeNull();+ expect(resolveNativePosition(1, [], [], [])).toBeNull();});});diff --git a/src/lib/ai-edition/timeline/timelineMap.ts b/src/lib/ai-edition/timeline/timelineMap.tsindex 2f3749ae7..b27103d6a 100644--- a/src/lib/ai-edition/timeline/timelineMap.ts+++ b/src/lib/ai-edition/timeline/timelineMap.ts@@ -402,7 +402,10 @@ export function anchorRegionsWithDerivedMs<export function segmentRawSpanSec(segment: PlaybackSegment,rawClips: AxcutClip[],- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): { startSec: number; endSec: number } {const startSec = getRawVirtualStartTime(segment, rawClips, insertRanges);// A held segment's source window is the single frame it shows, so its source length@@ -571,8 +574,10 @@ export function projectRegionsToSource</** The insertions the clips carry. A segment after one starts that much further along* the timeline, and an UNANCHORED region — a caption cue, which is built fresh each* time and has no clip anchor — is placed by intersecting with exactly that extent.- * Without them the caption landed on the wrong stretch of source (issue #560). */- insertRanges: readonly AxcutInsertRange[] = [],+ * Without them the caption landed on the wrong stretch of source (issue #560).+ *+ * REQUIRED for the same reason as its neighbours: omitting it is silently wrong. */+ insertRanges: readonly AxcutInsertRange[],): (T & { clipIndex?: number; underTrim?: boolean })[] {// RAW extents + owning raw clip per visible segment. Both are only consulted by the// path that needs them (raw fallback / anchor match), but resolving them once keeps@@ -688,7 +693,10 @@ export function resolveNativePosition(rawSec: number,visibleSegments: PlaybackSegment[],rawClips: AxcutClip[],- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): NativePosition | null {if (!Number.isFinite(rawSec) || visibleSegments.length === 0) return null;const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips, insertRanges));@@ -698,7 +706,7 @@ export function resolveNativePosition(const isLast = i === spans.length - 1;return rawSec >= s.startSec && (rawSec < s.endSec || (isLast && rawSec <= s.endSec));});- if (index < 0) return positionUnderCut(rawSec, visibleSegments, rawClips);+ if (index < 0) return positionUnderCut(rawSec, visibleSegments, rawClips, insertRanges);const seg = visibleSegments[index];// Inside a pause the source clock does not advance: the whole point of the segment@@ -733,6 +741,7 @@ function positionUnderCut(rawSec: number,visibleSegments: AxcutClip[],rawClips: AxcutClip[],+ insertRanges: readonly AxcutInsertRange[],): NativePosition {const rawClip = rawClipAt(rawSec, rawClips);if (rawClip) {@@ -757,7 +766,7 @@ function positionUnderCut(}}- const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips));+ const spans = visibleSegments.map((seg) => segmentRawSpanSec(seg, rawClips, insertRanges));const next = spans.findIndex((s) => s.startSec >= rawSec);const index = next >= 0 ? next : visibleSegments.length - 1;const seg = visibleSegments[index];diff --git a/src/lib/ai-edition/timeline/virtual-preview.test.ts b/src/lib/ai-edition/timeline/virtual-preview.test.tsindex f3dd64888..37bac870b 100644--- a/src/lib/ai-edition/timeline/virtual-preview.test.ts+++ b/src/lib/ai-edition/timeline/virtual-preview.test.ts@@ -51,24 +51,24 @@ describe("virtual-preview pure functions", () => {});it("locateVirtualPosition maps virtual time to source time", () => {- const pos = locateVirtualPosition(clips, 12);+ const pos = locateVirtualPosition(clips, 12, []);expect(pos).not.toBeNull();expect(pos?.clipIndex).toBe(1);expect(pos?.sourceTimeSec).toBe(22);});it("locateVirtualPosition returns null for empty clips", () => {- expect(locateVirtualPosition([], 0)).toBeNull();+ expect(locateVirtualPosition([], 0, [])).toBeNull();});it("locateSourcePosition maps source time back to virtual time", () => {- const pos = locateSourcePosition(clips, 25);+ const pos = locateSourcePosition(clips, 25, undefined, 0.05, undefined, []);expect(pos).not.toBeNull();expect(pos?.virtualTimeSec).toBe(15);});it("locateSourcePosition returns null for source time in a cut", () => {- expect(locateSourcePosition(clips, 15)).toBeNull();+ expect(locateSourcePosition(clips, 15, undefined, 0.05, undefined, [])).toBeNull();});it("keptWordIdSet flattens wordRefs from all clips", () => {@@ -106,13 +106,13 @@ describe("virtual-preview pure functions", () => {reason: "",},];- const pos1 = locateSourcePosition(multiClips, 5, "a1");+ const pos1 = locateSourcePosition(multiClips, 5, "a1", 0.05, undefined, []);expect(pos1?.clip.id).toBe("clip_1");- const pos2 = locateSourcePosition(multiClips, 5, "a2");+ const pos2 = locateSourcePosition(multiClips, 5, "a2", 0.05, undefined, []);expect(pos2?.clip.id).toBe("clip_2");- const posNone = locateSourcePosition(multiClips, 5, "a3");+ const posNone = locateSourcePosition(multiClips, 5, "a3", 0.05, undefined, []);expect(posNone).toBeNull();});@@ -148,19 +148,19 @@ describe("virtual-preview pure functions", () => {// the earliest matching clip — this is the bug: playing back the// second clip's segment would still report position/identity for the// first.- const ambiguous = locateSourcePosition(duplicateClips, 5, "a1");+ const ambiguous = locateSourcePosition(duplicateClips, 5, "a1", 0.05, undefined, []);expect(ambiguous?.clip.id).toBe("clip_1");// With the currently-active clip id passed through, it's preferred// even though clip_1 also matches (assetId, sourceTime).- const disambiguated = locateSourcePosition(duplicateClips, 5, "a1", 0.05, "clip_2");+ const disambiguated = locateSourcePosition(duplicateClips, 5, "a1", 0.05, "clip_2", []);expect(disambiguated?.clip.id).toBe("clip_2");expect(disambiguated?.virtualTimeSec).toBe(15);// A preferred clip id that no longer applies (source time moved// outside its range) falls back to the ambiguous scan rather than// forcing a stale match.- const outOfRange = locateSourcePosition(duplicateClips, 5, "a1", 0.05, "clip_3");+ const outOfRange = locateSourcePosition(duplicateClips, 5, "a1", 0.05, "clip_3", []);expect(outOfRange?.clip.id).toBe("clip_1");});@@ -213,6 +213,7 @@ describe("virtual-preview pure functions", () => {playingClip.assetId,0.05,playingClip.id,+ [],);expect(pos?.clip.id).toBe(playing);expect(pos?.virtualTimeSec).toBeCloseTo(playingClip.timelineStartSec + sourceTimeSec, 6);@@ -222,8 +223,8 @@ describe("virtual-preview pure functions", () => {// The scan cannot know which twin is playing — but its answer must at least not// depend on which twin happens to sit last in the array, which is what// `index === clips.length - 1` made it do.- const forward = locateSourcePosition(twins([a1, a2]), 9.96, "a1");- const reversed = locateSourcePosition(twins([a2, a1]), 9.96, "a1");+ const forward = locateSourcePosition(twins([a1, a2]), 9.96, "a1", 0.05, undefined, []);+ const reversed = locateSourcePosition(twins([a2, a1]), 9.96, "a1", 0.05, undefined, []);expect(forward?.clip.id).toBe("clip_a1");expect(reversed?.clip.id).toBe("clip_a2");// i.e. both resolve to the FIRST clip of the asset — the documented behaviour of@@ -246,17 +247,17 @@ describe("virtual-preview pure functions", () => {timelineEndSec: 20,},];- expect(locateSourcePosition(split, 10, "a1")?.clip.id).toBe("clip_a2");- expect(locateSourcePosition(split, 9.9, "a1")?.clip.id).toBe("clip_a1");+ expect(locateSourcePosition(split, 10, "a1", 0.05, undefined, [])?.clip.id).toBe("clip_a2");+ expect(locateSourcePosition(split, 9.9, "a1", 0.05, undefined, [])?.clip.id).toBe("clip_a1");// …and the very end of the timeline still resolves rather than falling off it.- expect(locateSourcePosition(split, 20, "a1")?.clip.id).toBe("clip_a2");+ expect(locateSourcePosition(split, 20, "a1", 0.05, undefined, [])?.clip.id).toBe("clip_a2");});it("ignores a named clip whose asset is not the one playing", () => {// A stale id during an asset swap must fall through to the scan rather than// mapping the time through media that is not on screen.const clips = twins([a1, c3]);- const pos = locateSourcePosition(clips, 5, "a1", 0.05, "clip_c3");+ const pos = locateSourcePosition(clips, 5, "a1", 0.05, "clip_c3", []);expect(pos?.clip.id).toBe("clip_a1");});});@@ -367,8 +368,8 @@ describe("virtual-preview pure functions", () => {timelineEndSec: 13.8,};- expect(getRawVirtualStartTime(segClip1Part2, rawClips)).toBe(6);- expect(getRawVirtualStartTime(segClip2Part1, rawClips)).toBe(13.2);+ expect(getRawVirtualStartTime(segClip1Part2, rawClips, [])).toBe(6);+ expect(getRawVirtualStartTime(segClip2Part1, rawClips, [])).toBe(13.2);});it("findNextKeptSegment finds next kept segment across multi-clip trim boundary", () => {@@ -421,11 +422,11 @@ describe("virtual-preview pure functions", () => {];// At current raw virtual time 2.5s (end of seg 0), next kept segment is seg 1 (clip_2)- const nextSeg = findNextKeptSegment(playbackClips, rawClips, 2.5, "a1", 2.5);+ const nextSeg = findNextKeptSegment(playbackClips, rawClips, 2.5, "a1", 2.5, undefined, []);expect(nextSeg).toBeDefined();expect(nextSeg?.id).toBe("clip_2");expect(nextSeg?.assetId).toBe("a2");- expect(getRawVirtualStartTime(nextSeg!, rawClips)).toBe(10.7);+ expect(getRawVirtualStartTime(nextSeg!, rawClips, [])).toBe(10.7);});describe("findNextKeptSegment never goes backwards", () => {@@ -473,9 +474,9 @@ describe("virtual-preview pure functions", () => {// clip_1 starts at source 30, which IS "later in source time", and its raw start// is 0: answering it sent playback back to the beginning, straight into the same// cut again, forever.- const next = findNextKeptSegment(playbackClips, rawClips, 17, "a1", 7, "clip_2");+ const next = findNextKeptSegment(playbackClips, rawClips, 17, "a1", 7, "clip_2", []);expect(next).toBeDefined();- expect(getRawVirtualStartTime(next!, rawClips)).toBe(20);+ expect(getRawVirtualStartTime(next!, rawClips, [])).toBe(20);expect(next?.sourceStartSec).toBe(10);});@@ -483,7 +484,7 @@ describe("virtual-preview pure functions", () => {// Same moment, but the raw position has not caught up (still reads 10, the start// of clip_2). The ruler test alone would answer clip_2's FIRST kept segment —// the stretch already played. The clip-scoped source test carries it past the cut.- const next = findNextKeptSegment(playbackClips, rawClips, 10, "a1", 7, "clip_2");+ const next = findNextKeptSegment(playbackClips, rawClips, 10, "a1", 7, "clip_2", []);expect(next?.sourceStartSec).toBe(10);});});diff --git a/src/lib/ai-edition/timeline/virtual-preview.ts b/src/lib/ai-edition/timeline/virtual-preview.tsindex 8448ae99d..ba27e8cfb 100644--- a/src/lib/ai-edition/timeline/virtual-preview.ts+++ b/src/lib/ai-edition/timeline/virtual-preview.ts@@ -23,7 +23,10 @@ export function clampVirtualTime(clips: AxcutClip[], value: number): number {export function locateVirtualPosition(clips: AxcutClip[],virtualTimeSec: number,- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): VirtualPosition | null {if (clips.length === 0) return null;const clamped = clampVirtualTime(clips, virtualTimeSec);@@ -81,7 +84,10 @@ export function findRawClipForSegment(export function getRawVirtualStartTime(segment: AxcutClip,rawClips: AxcutClip[],- insertRanges: readonly AxcutInsertRange[] = [],+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): number {const rawClip = findRawClipForSegment(segment, rawClips);if (!rawClip) return segment.timelineStartSec;@@ -114,12 +120,13 @@ export function findNextKeptSegment(playbackClips: AxcutClip[],rawClips: AxcutClip[],currentRawTime: number,- activeSourceId?: string,- currentSourceTime?: number,- activeClipId?: string,+ activeSourceId: string | undefined,+ currentSourceTime: number | undefined,+ activeClipId: string | undefined,+ insertRanges: readonly AxcutInsertRange[],): AxcutClip | undefined {for (const seg of playbackClips) {- const segRawStart = getRawVirtualStartTime(seg, rawClips);+ const segRawStart = getRawVirtualStartTime(seg, rawClips, insertRanges);if (segRawStart > currentRawTime + 0.001) {return seg;}@@ -188,8 +195,8 @@ function isWithinClipBounds(export function locateSourcePosition(clips: AxcutClip[],sourceTimeSec: number,- assetId?: string,- epsilon = 0.05,+ assetId: string | undefined,+ epsilon: number,// When two clips share the same source asset (and possibly overlapping// source ranges — a duplicated clip, or simply not trimmed yet), scanning// by (assetId, sourceTime) alone is ambiguous and always resolves to the@@ -198,8 +205,11 @@ export function locateSourcePosition(// which clip they're tracking (VirtualPreview, mid-playback) should pass// its id here so it's preferred whenever the source time still falls// inside it, before falling back to the ambiguous asset-wide scan.- preferredClipId?: string,- insertRanges: readonly AxcutInsertRange[] = [],+ preferredClipId: string | undefined,+ /** REQUIRED, not defaulted. A clip carrying insertions is longer than its source window,+ * so a caller that omits these gets an answer that is plausible and wrong by exactly the+ * inserted time, with nothing to catch it (issue #560). */+ insertRanges: readonly AxcutInsertRange[],): VirtualPosition | null {if (preferredClipId) {const preferredIndex = clips.findIndex((clip) => clip.id === preferredClipId);@@ -266,8 +276,12 @@ export function locateKeptSegment(const ownSegments = activeClipId? playbackClips.filter((seg) => findRawClipForSegment(seg, rawClips)?.id === activeClipId): [];- if (ownSegments.length > 0) return locateSourcePosition(ownSegments, sourceTimeSec, assetId);- return locateSourcePosition(playbackClips, sourceTimeSec, assetId);+ // The SEGMENTS are already split at every insertion, so within one of them source → its+ // own start is a plain shift again. `[]` here is the honest answer, not a forgotten+ // argument: there is no insertion inside a segment to account for.+ if (ownSegments.length > 0)+ return locateSourcePosition(ownSegments, sourceTimeSec, assetId, 0.05, undefined, []);+ return locateSourcePosition(playbackClips, sourceTimeSec, assetId, 0.05, undefined, []);}export function keptWordIdSet(clips: AxcutClip[]): Set<string> {diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 683066b69..6ede99478 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -575,7 +575,7 @@ export function buildSceneDescription(// Placed once: the projection below counts them, so a track after a pause lands where// the ruler says rather than D seconds early.const filmInserts = document.timeline.insertRanges ?? [];- const removed = removedRawSpans(projectedClips, document.timeline.trimRanges);+ const removed = removedRawSpans(projectedClips, document.timeline.trimRanges, filmInserts);// The take's pills, keyed by group. A voiceover is walked ONCE per pill and never per// stored fragment: the document keeps one fragment per clip a take covers, so walking// them separately would emit overlapping entries and `overlay_track_pcm` sums with `+=`diff --git a/src/native/useNativePlaybackSync.ts b/src/native/useNativePlaybackSync.tsindex f9d23c12c..7263d14a0 100644--- a/src/native/useNativePlaybackSync.ts+++ b/src/native/useNativePlaybackSync.ts@@ -36,7 +36,7 @@ export function useNativePlaybackSync(rawClips: readonly AxcutClip[],/** The insertions those clips carry — a clip is longer than its source window by them,* so a segment's place on the timeline cannot be found without them (issue #560). */- insertRanges: readonly AxcutInsertRange[] = [],+ insertRanges: readonly AxcutInsertRange[],): void {const activePosition = useMemo(() => resolveNativePosition(currentTimeSec, [...visibleSegments], [...rawClips], insertRanges),