Skip to content

Open source CapCut alternative.

TypeScript

feat(site): every member of a group drag rides the pointer

David Le371c2123dbf4
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index cd2be92a..0aa0a2ab 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -41,7 +41,7 @@ import {
import { originalSettings, type ExportDoc } from "@/cut/lib/exportClient";
import { useExports } from "@/cut/lib/exportStore";
import { isDragActive, startDrag, subscribeDragActive } from "@/cut/lib/drag";
-import { CLIP_GAP, startLaneMove, startLaneTrim, type LaneDrag, type LaneKind } from "@/cut/lib/laneTracks";
+import { CLIP_GAP, laneDragFor, laneDragParts, startLaneMove, startLaneTrim, type LaneDrag, type LaneKind } from "@/cut/lib/laneTracks";
import { downloadMedia, ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia, stripFailedFor, subscribeStripStatus } from "@/cut/lib/media";
import { planFilmstrip, type FilmTile } from "@/cut/lib/filmstrip";
import { track0Clips, laneGapAt, sameLane, type LaneRef, clipLen, clipSpeed, getClipSpans, overlayLaneOrder, overlayLayers, projectDuration, resolveTransitions, rippleInsert, useEditor } from "@/cut/lib/store";
@@ -2279,7 +2279,7 @@ export function Timeline() {
)}
{overlays.map((o) => {
const homeRow = overlayLanes.rowOf.get(o.lane ?? 0) ?? 0;
- const drag = laneDrag?.kind === "overlay" && laneDrag.id === o.id ? laneDrag : null;
+ const drag = laneDragFor(laneDrag, "overlay", o.id);
return (
<TextBar
key={o.id}
@@ -2297,7 +2297,7 @@ export function Timeline() {
laneCount={overlayLanes.count}
selected={selKeys.has(`overlay:${o.id}`)}
drag={drag}
- parting={laneDrag?.kind === "overlay" && laneDrag.id !== o.id}
+ parting={laneDragParts(laneDrag, "overlay", o.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
onMenu={setBarMenu}
@@ -2437,14 +2437,9 @@ export function Timeline() {
span={span}
pps={pps}
selected={selKeys.has(`clip:${span.clip.id}`)}
- drag={
- laneDrag?.kind === "overlayClip" && laneDrag.id === span.clip.id
- ? laneDrag
- : null
- }
+ drag={laneDragFor(laneDrag, "overlayClip", span.clip.id)}
parting={
- (laneDrag?.kind === "overlayClip" && laneDrag.id !== span.clip.id) ||
- videoDragActive
+ laneDragParts(laneDrag, "overlayClip", span.clip.id) || videoDragActive
}
partAt={dropPartAt.get(span.clip.id)}
onDrag={setLaneDrag}
@@ -2510,10 +2505,8 @@ export function Timeline() {
mention={`@c${i + 1}`}
pps={pps}
selected={selKeys.has(`clip:${span.clip.id}`)}
- drag={laneDrag?.kind === "clip" && laneDrag.id === span.clip.id ? laneDrag : null}
- parting={
- (laneDrag?.kind === "clip" && laneDrag.id !== span.clip.id) || videoDragActive
- }
+ drag={laneDragFor(laneDrag, "clip", span.clip.id)}
+ parting={laneDragParts(laneDrag, "clip", span.clip.id) || videoDragActive}
partAt={dropPartAt.get(span.clip.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
@@ -2598,7 +2591,7 @@ export function Timeline() {
)}
{audioClips.map((a) => {
const homeRow = audioLanes.rowOf.get(a.lane ?? 0) ?? 0;
- const drag = laneDrag?.kind === "audio" && laneDrag.id === a.id ? laneDrag : null;
+ const drag = laneDragFor(laneDrag, "audio", a.id);
return (
<AudioView
key={a.id}
@@ -2618,7 +2611,7 @@ export function Timeline() {
laneCount={audioLanes.count}
selected={selKeys.has(`audio:${a.id}`)}
drag={drag}
- parting={laneDrag?.kind === "audio" && laneDrag.id !== a.id}
+ parting={laneDragParts(laneDrag, "audio", a.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
/>
@@ -2665,8 +2658,8 @@ export function Timeline() {
top={(c.lane ?? 0) * SUB_H}
homeRow={c.lane ?? 0}
selected={selKeys.has(`cue:${c.id}`)}
- drag={laneDrag?.kind === "cue" && laneDrag.id === c.id ? laneDrag : null}
- parting={laneDrag?.kind === "cue" && laneDrag.id !== c.id}
+ drag={laneDragFor(laneDrag, "cue", c.id)}
+ parting={laneDragParts(laneDrag, "cue", c.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
/>
diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.ts
index 48b1ec04..23c83f7b 100644
--- a/site/src/cut/lib/laneTracks.ts
+++ b/site/src/cut/lib/laneTracks.ts
@@ -351,6 +351,27 @@ export interface LaneDrag {
/** Carried off its own lane set (an upper video layer headed elsewhere);
* the home slot preview hides while away. */
away?: boolean;
+ /** The rest of a group drag's set: each member rides the pointer as its own
+ * ghost, shifted by the same delta as the grabbed item. */
+ members?: { kind: LaneKind; id: string; ghostX: number }[];
+}
+
+/** The drag a bar renders with: the carried item's own LaneDrag, or — when
+ * the bar is another member of a group drag — a copy whose ghost carries that
+ * member's offset. Null for bars outside the drag. */
+export function laneDragFor(d: LaneDrag | null, kind: LaneKind, id: string): LaneDrag | null {
+ if (!d) return null;
+ if (d.kind === kind && d.id === id) return d;
+ const m = d.members?.find((x) => x.kind === kind && x.id === id);
+ return m ? { ...d, kind, id, ghostX: m.ghostX } : null;
+}
+
+/** True when a live drag moves items on this kind's lanes and this bar is
+ * outside the moving set: the bar animates the shifts that part it out of
+ * the way. */
+export function laneDragParts(d: LaneDrag | null, kind: LaneKind, id: string): boolean {
+ if (!d || laneDragFor(d, kind, id)) return false;
+ return d.kind === kind || !!d.members?.some((m) => m.kind === kind);
}
export interface LaneMoveUI<V = unknown> {
@@ -513,6 +534,10 @@ function startGroupMove(
const rowEl = (e.currentTarget as HTMLElement).parentElement;
const rowTop0 = rowEl?.getBoundingClientRect().top ?? 0;
+ // Everyone in the set but the grabbed item: each rides the pointer as its
+ // own ghost, so the whole selection visibly moves as one.
+ const riders = members.filter((m) => m.kind !== grabbed.kind || m.id !== grabbed.id);
+
let live = false;
let dt = 0;
let rowDelta = 0;
@@ -591,16 +616,25 @@ function startGroupMove(
rowDelta = vertical ? Math.min(rowHi, Math.max(rowLo, Math.round(dy / ui.rowH))) : 0;
ui.onSnap(guide);
layout(dt);
+ // Ghosts ride the raw pointer delta, clamped so the set's earliest
+ // member holds at 0 — the same rigid floor the landing uses.
+ const dtGhost = Math.max(-minStart, effDx / ui.pps);
+ const ghostY = dy - (rowEl ? rowEl.getBoundingClientRect().top - rowTop0 : 0);
ui.onDrag({
kind: grabbed.kind,
id: grabbed.id,
targetRow: homeRow + rowDelta,
minRow: homeRow + rowLo,
maxRow: homeRow + rowHi,
- ghostX: Math.max(0, grabbed.start + (effDx / ui.pps)) * ui.pps,
- ghostY: dy - (rowEl ? rowEl.getBoundingClientRect().top - rowTop0 : 0),
+ ghostX: (grabbed.start + dtGhost) * ui.pps,
+ ghostY,
slotStart: grabbed.start + dt,
len: grabbed.len,
+ members: riders.map((m) => ({
+ kind: m.kind,
+ id: m.id,
+ ghostX: (m.start + dtGhost) * ui.pps,
+ })),
});
},
onUp: (_dx, _dy, moved) => {