Skip to content

Commit bc4e7e3

Browse files
committed
fix(timeline): copy a whole pill, not the fragment clicked
A zoom, annotation, speed or Full Camera region cut by a clip boundary is several fragments drawn as one pill. Copying it took the fragment clicked, so the paste came out shorter than the region on screen. wholePillOf gives the pill as one region over its whole span; the shader effect copy, which had its own version of this, uses it too.
1 parent a6cd941 commit bc4e7e3

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

‎src/components/ai-edition/NewEditorShell.tsx‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,22 +1203,17 @@ export function NewEditorShell() {
12031203
return;
12041204
}
12051205

1206-
// An effect region goes with its definition (`RegionSnapshot`), and with the span of the
1207-
// whole pill: one cut by a clip boundary is several fragments.
1206+
// The pill on screen, not the fragment clicked: a region cut by a clip boundary is several.
1207+
const { wholePillOf } = await import("@/lib/ai-edition/timeline/timelineMap");
1208+
1209+
// An effect region goes with its definition (`RegionSnapshot`).
12081210
if (sel.kind === "shaderEffect") {
1209-
const { coalesceRegionsForRuler } = await import("@/lib/ai-edition/timeline/timelineMap");
1210-
const pill = coalesceRegionsForRuler(tl.shaderEffectRanges).find((p) =>
1211-
p.ids.includes(sel.id),
1212-
);
1213-
const definition = pill && tl.shaderEffects.find((e) => e.id === pill.member.effectId);
1214-
if (!pill || !definition) return;
1211+
const region = wholePillOf(tl.shaderEffectRanges, sel.id);
1212+
const definition = region && tl.shaderEffects.find((e) => e.id === region.effectId);
1213+
if (!region || !definition) return;
12151214
copyRegion({
12161215
kind: "shaderEffect",
1217-
region: {
1218-
...pill.member,
1219-
startMs: Math.round(pill.start * 1000),
1220-
endMs: Math.round(pill.end * 1000),
1221-
} as unknown as Record<string, unknown>,
1216+
region: region as unknown as Record<string, unknown>,
12221217
definition,
12231218
});
12241219
setCopiedClipId(null);
@@ -1233,7 +1228,10 @@ export function NewEditorShell() {
12331228
: sel.kind === "speed"
12341229
? tl.speedRegions
12351230
: tl.cameraFullscreenRegions;
1236-
const region = (source as Array<{ id: string }>).find((r) => r.id === sel.id);
1231+
const region = wholePillOf(
1232+
source as Array<{ id: string; startMs: number; endMs: number }>,
1233+
sel.id,
1234+
);
12371235
if (!region) return;
12381236
copyRegion({ kind: sel.kind, region: region as unknown as Record<string, unknown> });
12391237
// One clipboard wins at a time: a copied pill retires the copied clip.

‎src/lib/ai-edition/timeline/timelineMap.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
resolveNativePosition,
1919
resolvePillIds,
2020
resolveRegionIds,
21+
wholePillOf,
2122
} from "./timelineMap";
2223

2324
function clip(overrides: Partial<AxcutClip> & Pick<AxcutClip, "id" | "assetId">): AxcutClip {
@@ -787,6 +788,18 @@ describe("pills wired to the universal rules", () => {
787788
expect(pills[0].ids).toEqual(["a", "b"]);
788789
});
789790

791+
it("wholePillOf gives the pill a fragment belongs to, over its whole span", () => {
792+
// One zoom cut by the clip boundary at 25.557 s: two fragments, one pill.
793+
const regions = [
794+
{ id: "a", startMs: 20000, endMs: 25557, depth: 3 },
795+
{ id: "b", startMs: 25557, endMs: 30000, depth: 3 },
796+
{ id: "c", startMs: 30000, endMs: 31000, depth: 5 },
797+
];
798+
expect(wholePillOf(regions, "b")).toEqual({ id: "a", startMs: 20000, endMs: 30000, depth: 3 });
799+
expect(wholePillOf(regions, "c")).toEqual(regions[2]);
800+
expect(wholePillOf(regions, "gone")).toBeNull();
801+
});
802+
790803
it("keeps adjacent regions with different properties as separate pills", () => {
791804
const pills = coalesceRegionsForRuler([
792805
{ id: "a", startMs: 2000, endMs: 5000, speed: 3 },

‎src/lib/ai-edition/timeline/timelineMap.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,24 @@ export function coalesceRegionsForRuler<T extends { id: string; startMs: number;
304304
}));
305305
}
306306

307+
/**
308+
* The pill `id` belongs to, as one region: its first member over the pill's whole span. A pill
309+
* cut by a clip boundary is several fragments, and copying the fragment clicked would paste a
310+
* shorter region than the one on screen. `null` when no region has that id.
311+
*/
312+
export function wholePillOf<T extends { id: string; startMs: number; endMs: number }>(
313+
regions: T[],
314+
id: string,
315+
): T | null {
316+
const pill = coalesceRegionsForRuler(regions).find((p) => p.ids.includes(id));
317+
if (!pill) return null;
318+
return {
319+
...pill.member,
320+
startMs: Math.round(pill.start * 1000),
321+
endMs: Math.round(pill.end * 1000),
322+
};
323+
}
324+
307325
/**
308326
* The regions that render as the SAME pill as `id`. Recomputed from the merge rule
309327
* rather than stored: nothing records which regions belong together, because equal

0 commit comments

Comments
 (0)