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
29 changes: 28 additions & 1 deletion electron/ai-edition/document-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe("DocumentService", () => {
});

describe("removeAsset", () => {
it("removes the asset and cascades clips + trimRanges", async () => {
it("removes the asset and cascades clips, trims, and clip modifiers", async () => {
const doc = await service.createProject("P");
const withAsset = await service.addAsset(doc.project.id, { path: "/tmp/a.mp4" });
const assetId = withAsset.assets[0]?.id ?? "";
Expand Down Expand Up @@ -174,12 +174,39 @@ describe("DocumentService", () => {
},
],
},
zoomRanges: [
{
id: "zoom_1",
clipId: "clip_1",
sourceStartSec: 0,
sourceEndSec: 1,
startMs: 0,
endMs: 1000,
depth: 3,
focus: { cx: 0.5, cy: 0.5 },
},
],
legacyEditor: {
speedRegions: [
{
id: "speed_1",
clipId: "clip_1",
sourceStartSec: 0,
sourceEndSec: 1,
startMs: 0,
endMs: 1000,
speed: 2,
},
],
},
});

const after = await service.removeAsset(docWithTimeline.project.id, assetId);
expect(after.assets).toHaveLength(0);
expect(after.timeline.clips).toHaveLength(0);
expect(after.timeline.trimRanges).toHaveLength(0);
expect(after.zoomRanges).toHaveLength(0);
expect((after.legacyEditor as { speedRegions: unknown[] }).speedRegions).toHaveLength(0);
expect(after.project.primaryAssetId).toBeUndefined();
});

Expand Down
13 changes: 8 additions & 5 deletions electron/ai-edition/document-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import fs, { type FileHandle } from "node:fs/promises";
import path from "node:path";
import { createId } from "../../src/lib/ai-edition/document/ids";
import { removeClip } from "../../src/lib/ai-edition/document/timeline";
import {
type AxcutAsset,
type AxcutDocument,
Expand Down Expand Up @@ -309,16 +310,18 @@ export class DocumentService {
doc.project.primaryAssetId === assetId
? (assets[0]?.id ?? undefined)
: doc.project.primaryAssetId;
const withoutAssetClips = doc.timeline.clips
Comment thread
EtienneLescot marked this conversation as resolved.
.filter((clip) => clip.assetId === assetId)
.reduce((current, clip) => removeClip(current, clip.id), doc);
const next: AxcutDocument = {
...doc,
...withoutAssetClips,
assets,
timeline: {
...doc.timeline,
clips: doc.timeline.clips.filter((c) => c.assetId !== assetId),
trimRanges: doc.timeline.trimRanges.filter((r) => r.assetId !== assetId),
...withoutAssetClips.timeline,
trimRanges: withoutAssetClips.timeline.trimRanges.filter((r) => r.assetId !== assetId),
},
project: {
...doc.project,
...withoutAssetClips.project,
primaryAssetId,
updatedAt: new Date().toISOString(),
},
Expand Down
82 changes: 82 additions & 0 deletions src/lib/ai-edition/document/timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,88 @@ describe("removeClip — delete a clip, close the gap, drop its pills", () => {
expect(next.zoomRanges[0]).toMatchObject({ startMs: 2000, endMs: 4000 });
});

it("drops every modifier anchored to the last remaining clip", () => {
const before = makeDoc({
timeline: {
...makeDoc().timeline,
clips: [
makeClip({ id: "clip_a", sourceStartSec: 0, sourceEndSec: 10, timelineEndSec: 10 }),
],
},
zoomRanges: [
makeZoom({ id: "anchored_zoom", clipId: "clip_a", sourceEndSec: 1, endMs: 1000 }),
makeZoom({
id: "legacy_zoom",
clipId: undefined,
sourceStartSec: undefined,
sourceEndSec: undefined,
}),
],
annotations: [
{
id: "anchored_annotation",
clipId: "clip_a",
sourceStartSec: 0,
sourceEndSec: 1,
startMs: 0,
endMs: 1000,
type: "text",
content: "remove me",
position: { x: 50, y: 50 },
size: { width: 30, height: 20 },
style: {
color: "#fff",
backgroundColor: "transparent",
fontSize: 32,
fontFamily: "Inter",
fontWeight: "bold",
fontStyle: "normal",
textDecoration: "none",
textAlign: "center",
textAnimation: "none",
},
zIndex: 1,
},
] as unknown as AxcutDocument["annotations"],
legacyEditor: {
speedRegions: [
{
id: "anchored_speed",
clipId: "clip_a",
sourceStartSec: 0,
sourceEndSec: 1,
startMs: 0,
endMs: 1000,
speed: 2,
},
{ id: "legacy_speed", startMs: 0, endMs: 1000, speed: 1.5 },
],
cameraFullscreenRegions: [
{
id: "anchored_camera",
clipId: "clip_a",
sourceStartSec: 0,
sourceEndSec: 1,
startMs: 0,
endMs: 1000,
},
],
},
});

const next = removeClip(before, "clip_a");

expect(next.timeline.clips).toEqual([]);
expect(next.zoomRanges.map((region) => region.id)).toEqual(["legacy_zoom"]);
expect(next.annotations).toEqual([]);
expect((next.legacyEditor as { speedRegions: Array<{ id: string }> }).speedRegions).toEqual([
expect.objectContaining({ id: "legacy_speed" }),
]);
expect(
(next.legacyEditor as { cameraFullscreenRegions: unknown[] }).cameraFullscreenRegions,
).toEqual([]);
});

it("is a no-op for an unknown clip", () => {
const before = doc();
const next = removeClip(before, "clip_missing");
Expand Down
7 changes: 6 additions & 1 deletion src/lib/ai-edition/document/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,12 @@ export function removeClip(document: AxcutDocument, clipId: string): AxcutDocume
trimRanges: document.timeline.trimRanges.filter((t) => t.clipId !== clipId),
},
};
return oldClips.length > 0 && newClips.length > 0 ? rederiveRegionMs(next, newClips) : next;
const withoutRemovedRegions = mapAllRegionCollections(next, (regions) =>
regions.filter((region) => region.clipId !== clipId),
Comment thread
EtienneLescot marked this conversation as resolved.
);
return newClips.length > 0
? rederiveRegionMs(withoutRemovedRegions, newClips)
: withoutRemovedRegions;
}

export function restoreFullTimeline(document: AxcutDocument): AxcutDocument {
Expand Down
Loading