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(timeline): copy and paste trims too
Etienne Lescotab4fc45b520b
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsxindex a6abd249b..56a220d0b 100644--- a/src/components/ai-edition/NewEditorShell.tsx+++ b/src/components/ai-edition/NewEditorShell.tsx@@ -710,6 +710,16 @@ export function NewEditorShell() {const { pasteClipboard } = await import("@/lib/ai-edition/store/regionClipboard");const snapshot = pasteClipboard();if (!snapshot) return;++ // A copied trim is just a length: recreate one of that length at the+ // playhead, through the same call the toolbar's cut button uses (which+ // resolves the timeline span down to the carrying clip's source time).+ if (snapshot.kind === "trim") {+ await tl.addTrim(snapshot.region.durationSec);+ toast.success("Region pasted");+ return;+ }+const { anchorRegionsWithDerivedMs } = await import("@/lib/ai-edition/timeline/timelineMap");const { createId } = await import("@/lib/ai-edition/document/ids");@@ -754,19 +764,37 @@ export function NewEditorShell() {});}toast.success("Region pasted");- }, [saveDocument]);+ // `tl` belongs here now that the trim branch calls tl.addTrim: useTimeline+ // returns a fresh object each render, so memoizing on saveDocument alone+ // would paste through a callback holding a stale document.+ }, [saveDocument, tl]);// Copy the SELECTED pill. Reads the same arrays the lanes render, so what gets// copied is what the user is looking at — the old version dug into the raw// document with a ternary chain that mapped a trim to "zoom" and sent// cameraFullscreen down the speed branch, where neither could ever be found.- //- // Trims stay out: they are stored in SOURCE time against a clip anchor, so- // pasting one at the playhead is a ventilation problem, not a copy. Cut- // already excludes them for the same reason.const handleCopyRegion = useCallback(async () => {const sel = tl.selection;- if (!sel || sel.kind === "trim") return;+ if (!sel) return;+ const { copyRegion } = await import("@/lib/ai-edition/store/regionClipboard");++ // A trim is stored in SOURCE time against a clip anchor, so there is no+ // row to clone — but there is nothing to clone either: what the user means+ // by copying a cut is its LENGTH. Paste then makes a fresh trim of that+ // length at the playhead, which is the same deal every other kind gets+ // (properties kept, position taken from the playhead).+ if (sel.kind === "trim") {+ const { coalescedTrimGroups } = await import("@/lib/ai-edition/timeline/trim-mapping");+ const group = coalescedTrimGroups(tl.trimRanges, tl.clips).find((g) =>+ g.ids.includes(sel.id),+ );+ if (!group) return;+ copyRegion({ kind: "trim", region: { durationSec: group.end - group.start } });+ setCopiedClipId(null);+ toast.success("Region copied");+ return;+ }+const source =sel.kind === "zoom"? tl.zoomRegions@@ -777,7 +805,6 @@ export function NewEditorShell() {: tl.cameraFullscreenRegions;const region = (source as Array<{ id: string }>).find((r) => r.id === sel.id);if (!region) return;- const { copyRegion } = await import("@/lib/ai-edition/store/regionClipboard");copyRegion({ kind: sel.kind, region: region as unknown as Record<string, unknown> });// One clipboard wins at a time: a copied pill retires the copied clip.setCopiedClipId(null);@@ -876,7 +903,8 @@ export function NewEditorShell() {}if (ctrl && e.key.toLowerCase() === "x") {// F2.8 — cut: remember the region in the clipboard, then remove it.- if (tl.selection && tl.selection.kind !== "trim") {+ // Trims included now that copying one means copying its length.+ if (tl.selection) {e.preventDefault();const cut = tl.selection;void handleCopyRegion().then(() => tl.removeRegion(cut.kind, cut.id));diff --git a/src/lib/ai-edition/store/regionClipboard.ts b/src/lib/ai-edition/store/regionClipboard.tsindex 87936d905..ef1116ff8 100644--- a/src/lib/ai-edition/store/regionClipboard.ts+++ b/src/lib/ai-edition/store/regionClipboard.ts@@ -10,7 +10,13 @@ export type RegionSnapshot =| { kind: "zoom"; region: Record<string, unknown> }| { kind: "annotation"; region: Record<string, unknown> }| { kind: "speed"; region: Record<string, unknown> }- | { kind: "cameraFullscreen"; region: Record<string, unknown> };+ | { kind: "cameraFullscreen"; region: Record<string, unknown> }+ // A trim carries no user-visible properties, so all there is to copy is how+ // LONG it was — `{ durationSec }`. That is not a special case so much as the+ // general one made obvious: every paste keeps the copied properties and takes+ // its start from the playhead, so a zoom's start/end already change too. A+ // trim just has nothing left once you remove position.+ | { kind: "trim"; region: { durationSec: number } };let clipboard: RegionSnapshot | null = null;const listeners = new Set<() => void>();diff --git a/src/lib/ai-edition/store/useTimeline.test.ts b/src/lib/ai-edition/store/useTimeline.test.tsindex fa9b26724..ca1edf898 100644--- a/src/lib/ai-edition/store/useTimeline.test.ts+++ b/src/lib/ai-edition/store/useTimeline.test.ts@@ -612,6 +612,21 @@ describe("useTimeline is not re-rendered by playhead ticks", () => {});});+ // Pasting a copied trim is exactly this call: a trim carries no properties, so+ // all a copy holds is its length, and paste recreates one that long at the+ // playhead. Same primitive the toolbar's cut button uses.+ it("creates a trim of the requested length", async () => {+ const { result } = renderTimeline();+ act(() => {+ useProjectStore.getState().setCurrentTime(3);+ });+ await act(async () => {+ await result.current.addTrim(1.25);+ });+ const trim = useProjectStore.getState().document?.timeline.trimRanges.at(-1);+ expect((trim?.endSec ?? 0) - (trim?.startSec ?? 0)).toBeCloseTo(1.25, 6);+ });+// The timeline's toolbar passes a duration worth a fixed number of pixels at// the current zoom; every other entry point keeps the 2 s above.it("honours a caller-supplied duration", async () => {