Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/lib/ai-edition/document/insertion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ describe("insertGeneratedClip", () => {
[5, 10],
]);
});

it("keeps the speed and Full Camera regions of the right half, and both sides of one across the cut (#1037)", () => {
const region = (id: string, startSec: number, endSec: number) => ({
id,
clipId: "c1",
sourceStartSec: startSec,
sourceEndSec: endSec,
startMs: startSec * 1000,
endMs: endSec * 1000,
});
const next = withInsertion(
doc({
legacyEditor: {
speedRegions: [
{ ...region("right", 6, 8), speed: 2 },
{ ...region("across", 3, 5), speed: 2 },
],
cameraFullscreenRegions: [region("right", 7, 9), region("across", 3, 5)],
},
} as Partial<AxcutDocument>),
);
const rightId = next.timeline.clips[2].id;
const spans = (rows: unknown) =>
(rows as { clipId: string; sourceStartSec: number; sourceEndSec: number }[])
.map((r) => [r.clipId === rightId ? "right" : r.clipId, r.sourceStartSec, r.sourceEndSec])
.sort((a, b) => Number(a[1]) - Number(b[1]));
const legacy = next.legacyEditor as Record<string, unknown>;
expect(spans(legacy.speedRegions)).toEqual([
["c1", 3, 4],
["right", 4, 5],
["right", 6, 8],
]);
expect(spans(legacy.cameraFullscreenRegions)).toEqual([
["c1", 3, 4],
["right", 4, 5],
["right", 7, 9],
]);
});
});

describe("removeGeneratedClips", () => {
Expand Down
12 changes: 7 additions & 5 deletions src/lib/ai-edition/document/insertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
isGeneratedAssetId,
} from "../timeline/clip-parts";
import { createId } from "./ids";
import { rederiveRegionMs, removeClip, resequenceClips } from "./timeline";
import { mapAllRegionCollections, rederiveRegionMs, removeClip, resequenceClips } from "./timeline";

/** Where a new word goes relative to the word the caret was resting on. */
export type InsertSide = "before" | "after";
Expand Down Expand Up @@ -133,11 +133,13 @@ function fanOutAnchors(document: AxcutDocument, from: string, to: string): Axcut
(rows ?? []).flatMap((row) =>
row.clipId === from ? [row, { ...row, id: createId("frag"), clipId: to }] : [row],
);
// Every modifier collection, through the one walk that knows them all (#1037: a hand-picked
// list here forgot speed and Full Camera). Audio is kept out of it and fanned out on its own:
// that walk also re-anchors the takes, which is `rederiveRegionMs`'s job once the ms are fresh.
const fanned = mapAllRegionCollections({ ...document, audioTracks: [] }, both);
return {
...document,
timeline: { ...document.timeline, trimRanges: both(document.timeline.trimRanges) },
zoomRanges: both(document.zoomRanges),
annotations: both(document.annotations),
...fanned,
timeline: { ...fanned.timeline, trimRanges: both(fanned.timeline.trimRanges) },
audioTracks: both(document.audioTracks),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ai-edition/document/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ type StoredRegion = {
};

/** Apply `fn` to all four modifier collections (document-level + legacyEditor envelopes). */
function mapAllRegionCollections(
export function mapAllRegionCollections(
document: AxcutDocument,
fn: (regions: StoredRegion[], prefix: string) => StoredRegion[],
): AxcutDocument {
Expand Down
Loading