Open source CapCut alternative.
TypeScript
fix(site): deleting the footage leaves the elements standing [rebuild]
David Le83e87cce8e6d
diff --git a/site/src/cut/lib/store.test.ts b/site/src/cut/lib/store.test.tsindex 53c3cfc3..d1bb634d 100644--- a/site/src/cut/lib/store.test.ts+++ b/site/src/cut/lib/store.test.ts@@ -709,6 +709,44 @@ describe("delete ripple and gaps", () => {expect(clipById(b.id).transition).toBeCloseTo(0.5);});+ test("clearing track 0 leaves the titles and captions standing", () => {+ const a = vclip({ track: 0, start: 0, out: 2 });+ const b = vclip({ track: 0, start: 2, out: 2 });+ const t = title({ start: 1, end: 3 });+ const au = aclip({ start: 1, out: 2 });+ useEditor.setState({+ clips: [a, b],+ audioClips: [au],+ overlays: [t],+ multiSelection: [+ { kind: "clip", id: a.id },+ { kind: "clip", id: b.id },+ ],+ selection: { kind: "clip", id: b.id },+ });+ s().deleteSelection();+ expect(s().clips).toEqual([]);+ // No footage left means no hole to close, so nothing laid over it moves+ // and nothing goes with it.+ expect(s().overlays.map((o) => o.id)).toEqual([t.id]);+ expect(s().overlays[0].start).toBeCloseTo(1);+ expect(audioById(au.id).start).toBeCloseTo(1);+ });++ test("deleting the only clip keeps the elements written over it", () => {+ const only = vclip({ track: 0, start: 0, out: 6 });+ const t = title({ start: 1, end: 3 });+ useEditor.setState({+ clips: [only],+ overlays: [t],+ selection: { kind: "clip", id: only.id },+ });+ s().deleteSelection();+ expect(s().clips).toEqual([]);+ expect(s().overlays.map((o) => o.id)).toEqual([t.id]);+ expect(s().overlays[0].start).toBeCloseTo(1);+ });+test("delete with an overlay video track leaves the gap in place", () => {const a = vclip({ track: 0, start: 0, out: 2 });const b = vclip({ track: 0, start: 2, out: 2 });diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex c9d25edf..92a9eb1b 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -564,12 +564,14 @@ export interface EditorState {* from the original recording, so the word highlighter would otherwise drift). */retimeCues: (entries: { id: string; start: number; end: number }[]) => void;sortCues: () => void;- /** Delete the current selection. While track 0 is the only video track, a- * track-0 clip delete ripples: the footprint it occupied closes and- * everything after it — clips, titles, captions, soundtrack — slides left- * in sync (see exciseRange). With upper video layers present the slide- * would shear them against track 0, so the delete leaves the gap; closing- * it is `removeLaneGap`. Deletes on every other track remove just that item. */+ /** Delete the current selection. While track 0 is the only video track and+ * some of its footage survives, a track-0 clip delete ripples: the footprint+ * it occupied closes and everything after it — clips, titles, captions,+ * soundtrack — slides left in sync (see exciseRange). With upper video+ * layers present the slide would shear them against track 0, and with track+ * 0 emptied there is nothing left for the close to keep contiguous, so both+ * leave the gap and everything laid over the footage stands; closing it is+ * `removeLaneGap`. Deletes on every other track remove just that item. */deleteSelection: () => void;/** Close the empty span on `lane` containing `at` — a video track, an audio* track, or a title track. Only that row's later items slide left; every@@ -3055,19 +3057,23 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {// Deleting a track-0 clip closes the hole it leaves: everything after// it — clips, titles, captions, soundtrack — slides left with the// surviving footage, and anything living inside the hole annotated- // footage that is gone, so it goes too. That ripple runs only while- // track 0 is the only video track: with upper layers surviving, the- // slide would shear them against the footage they were composed over,- // so the delete leaves the gap and closing it is an explicit act- // (removeGap, via right-click on the empty space). Deletes on every- // other track are plain removals (already applied above). Holes close- // right-to-left so each one's coordinates stay valid while the ones- // before it are unprocessed.- const holes = clips.some((c) => c.track !== 0)- ? []- : s.clips+ // footage that is gone, so it goes too. Two conditions gate that+ // ripple. Track 0 has to be the only video track, since with upper+ // layers surviving the slide would shear them against the footage they+ // were composed over. And some track-0 footage has to survive the+ // delete: clearing the whole track leaves no hole to close, and closing+ // it anyway would carry every title, card and caption in the project+ // into the excision. Either way the delete leaves the gap and closing+ // it is an explicit act (removeGap, via right-click on the empty+ // space). Deletes on every other track are plain removals (already+ // applied above). Holes close right-to-left so each one's coordinates+ // stay valid while the ones before it are unprocessed.+ const rippling = clips.some((c) => c.track === 0) && !clips.some((c) => c.track !== 0);+ const holes = rippling+ ? s.clips.filter((c) => c.track === 0 && clipIds.has(c.id))- .sort((a, b) => b.start - a.start);+ .sort((a, b) => b.start - a.start)+ : [];for (const gone of holes) {const next = clips.reduce((acc, c) => (c.track === 0 && c.start > gone.start + 0.001 ? Math.min(acc, c.start) : acc),