Skip to content

Open source CapCut alternative.

TypeScript

feat(site): timeline drags ripple into place and close vacated gaps

David Le53ff2d933ac8
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index e1fb0726..7a8e6030 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -41,7 +41,7 @@ import { useExports } from "@/cut/lib/exportStore";
import { isDragActive, startDrag, subscribeDragActive } from "@/cut/lib/drag";
import { CLIP_GAP, startLaneMove, startLaneTrim, type LaneDrag } from "@/cut/lib/laneTracks";
import { downloadMedia, ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia } from "@/cut/lib/media";
-import { track0Clips, laneGapAt, sameLane, type LaneRef, clipLen, clipSpeed, footprints, getClipSpans, nextFreeStart, overlayLaneOrder, overlayLayers, projectDuration, resolveTransitions, rippleInsert, useEditor } from "@/cut/lib/store";
+import { track0Clips, laneGapAt, sameLane, type LaneRef, clipLen, clipSpeed, getClipSpans, overlayLaneOrder, overlayLayers, projectDuration, resolveTransitions, rippleInsert, useEditor } from "@/cut/lib/store";
import type { VideoTrackPlacement } from "@/cut/lib/store";
import { playheadAt, setSkim, skimAt, subscribePlayhead, usePlayhead, useSkim } from "@/cut/lib/playhead";
import { laneHidden, subtitleLaneCount } from "@/cut/lib/subtitles";
@@ -508,22 +508,44 @@ export function Timeline() {
// clip would land, how long it runs, and what the source looks like, so the
// preview reads as the segment itself sliding along the row rather than an
// empty slot.
- const [assetDrop, setAssetDrop] = useState<{ t: number; len: number; ghost?: DropGhost } | null>(
- null
- );
+ const [assetDrop, setAssetDrop] = useState<{
+ t: number;
+ len: number;
+ ghost?: DropGhost;
+ shifts?: { id: string; start: number }[];
+ } | null>(null);
// Kind of external media being dragged over the timeline (audio vs video).
const [dropType, setDropType] = useState<"video" | "audio" | null>(null);
// A video clip is being dragged (internal or external): reveals the
// would-be new tracks past the stack's edges.
const [videoDragging, setVideoDragging] = useState(false);
- // The pending drop preview: which track/gap, at what time, for how long.
- const [overlayDrop, setOverlayDrop] = useState<
- { target: TrackTarget; t: number; len: number } | null
- >(null);
+ // The pending drop preview: which track/gap, at what time, for how long —
+ // and which resident clips slide right to open the room, so the row can
+ // paint them parting ahead of the drop.
+ const [overlayDrop, setOverlayDrop] = useState<{
+ target: TrackTarget;
+ t: number;
+ len: number;
+ shifts?: { id: string; start: number }[];
+ /** External media paints its landing as the segment itself — filmstrip at
+ * true length; without one the slot is the plain highlight (internal drags
+ * already carry their own clip). */
+ ghost?: DropGhost;
+ } | null>(null);
// Stage-x pixel a snapped title edge sits at, for the guide line (null = off).
const [snapX, setSnapX] = useState<number | null>(null);
const videoDragActive = videoDragging || dropType === "video";
+ // Residents sliding ahead of an in-flight drop: clip id → the start it
+ // previews at. Painted as an animated left offset, so the row opens room
+ // while the drop hovers and flows back the moment the drag aims elsewhere.
+ const dropPartAt = useMemo(() => {
+ const m = new Map<string, number>();
+ for (const sh of assetDrop?.shifts ?? []) m.set(sh.id, sh.start);
+ for (const sh of overlayDrop?.shifts ?? []) m.set(sh.id, sh.start);
+ return m;
+ }, [assetDrop, overlayDrop]);
+
// Which drop the cursor is over: an existing track (0 included), or a
// would-be new track — past the stack's edges, or at a seam between rows.
// Hit-test live via elementFromPoint — rows (new-track rows included) carry
@@ -579,18 +601,21 @@ export function Timeline() {
// target track's slot or a between-track insertion line. An existing track
// takes the drop as an insert at the pointer — its later clips ripple right —
// so the slot previews the ripple landing the drop will actually take.
- const previewCross = useCallback((target: TrackTarget | null, start = 0, len = 0) => {
- if (target === null) return setOverlayDrop(null);
- const t =
- target.kind === "track"
- ? rippleInsert(
- useEditor.getState().clips.filter((c) => c.track === target.track),
- Math.max(0, start),
- len
- ).start
- : start;
- setOverlayDrop({ target, t, len });
- }, []);
+ const previewCross = useCallback(
+ (target: TrackTarget | null, start = 0, len = 0, ghost?: DropGhost) => {
+ if (target === null) return setOverlayDrop(null);
+ const landing =
+ target.kind === "track"
+ ? rippleInsert(
+ useEditor.getState().clips.filter((c) => c.track === target.track),
+ Math.max(0, start),
+ len
+ )
+ : { start, shifts: [] };
+ setOverlayDrop({ target, t: landing.start, len, shifts: landing.shifts, ghost });
+ },
+ []
+ );
// Releasing a track-0 clip on any other track lifts it out onto that track
// (or a new one); on its own track the lane coordinator commits the move.
@@ -1216,22 +1241,59 @@ export function Timeline() {
};
// The video being dragged — project media, a library clip, or an image ref
- // (which lands as a still).
- const draggedVideo = (e: React.DragEvent): { duration: number } | null => {
+ // (which lands as a still) — with the ghost its landing segment paints.
+ const draggedVideo = (e: React.DragEvent): { duration: number; ghost: DropGhost } | null => {
if (hasLibraryDrag(e)) {
const lib = draggingLibrary();
if (!lib || !isClipMedia(lib.type)) return null;
- return { duration: lib.type === "image" ? STILL_SECONDS : lib.duration };
+ return {
+ duration: lib.type === "image" ? STILL_SECONDS : lib.duration,
+ ghost: {
+ url: libraryMediaUrl(lib.fileName, lib.residency),
+ kind: lib.type,
+ aspect: lib.width && lib.height ? lib.width / lib.height : undefined,
+ },
+ };
}
const id = draggingAssetId();
if (id) {
const asset = useEditor.getState().assets.find((a) => a.id === id);
if (!asset || stickerOf(asset) || !isClipMedia(asset.type)) return null;
- return { duration: asset.type === "image" ? STILL_SECONDS : asset.duration };
+ return {
+ duration: asset.type === "image" ? STILL_SECONDS : asset.duration,
+ ghost:
+ asset.type === "image"
+ ? { url: asset.url, kind: "image" }
+ : {
+ url: asset.url,
+ kind: "video",
+ aspect:
+ asset.width && asset.height ? asset.width / asset.height : undefined,
+ thumbs: asset.thumbs,
+ thumbStep: asset.thumbStep,
+ poster: asset.thumbs?.[0],
+ },
+ };
}
const stockVideo = draggingStockVideo(e);
- if (stockVideo) return { duration: stockVideo.duration ?? 0 };
- return draggingStill(e) ? { duration: STILL_SECONDS } : null;
+ if (stockVideo) {
+ return {
+ duration: stockVideo.duration ?? 0,
+ ghost: {
+ url: stockVideo.url,
+ kind: "video",
+ aspect:
+ stockVideo.width && stockVideo.height
+ ? stockVideo.width / stockVideo.height
+ : undefined,
+ poster: stockVideo.thumb,
+ },
+ };
+ }
+ const still = draggingStill(e);
+ return still
+ ? { duration: STILL_SECONDS, ghost: { url: still.url, kind: "image" } }
+ : null;
};
// Drop targets for the upper tracks and between-track seams: dragging a
@@ -1251,7 +1313,8 @@ export function Timeline() {
previewCross(
resolveDropTrack(e.clientX, e.clientY),
Math.max(0, timeAt(e.clientX)),
- vid.duration
+ vid.duration,
+ vid.ghost
);
},
onDragLeave: (e: React.DragEvent) => {
@@ -1316,18 +1379,40 @@ export function Timeline() {
});
};
- // The landing-slot preview on a video row while the drag targets it — the
- // same chrome as the lane slots.
+ // The dragged media as a floating segment: its filmstrip fills it at true
+ // length and it rides above the row's clips (z-20), so the drag reads as a
+ // placed segment sliding to its landing spot.
+ const dropSegment = (t: number, len: number, h: number, ghost?: DropGhost) => (
+ <div
+ className="tl-asset-drop-slot pointer-events-none absolute top-0.5 z-20 overflow-hidden rounded-lg bg-black opacity-90 shadow-2xl ring-[1.5px] ring-[#0a84ff]/70 transition-[left] duration-100 ease-out"
+ style={{ left: t * pps, width: Math.max(10, len * pps - CLIP_GAP), height: h }}
+ >
+ {ghost && (
+ <DropGhostFilm ghost={ghost} w={Math.max(10, len * pps - CLIP_GAP)} h={h} pps={pps} />
+ )}
+ <span className="absolute top-1 left-1 rounded-[5px] bg-black/65 px-1.5 py-px font-mono text-[10px] tabular-nums text-white">
+ {len.toFixed(1)}s
+ </span>
+ </div>
+ );
+
+ // The landing preview on a video row while the drag targets it. External
+ // media paints the segment itself; an internal drag paints the plain slot —
+ // the same chrome as the lane slots — since the dragged clip is its own ghost.
const trackSlot = (place: TrackTarget, h: number) =>
samePlacement(overlayDrop?.target ?? null, place) ? (
- <div
- className="pointer-events-none absolute top-0.5 rounded-lg bg-[#0a84ff]/10 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.4)] transition-[left] duration-150 ease-out"
- style={{
- left: overlayDrop!.t * pps,
- width: Math.max(10, overlayDrop!.len * pps - CLIP_GAP),
- height: h,
- }}
- />
+ overlayDrop!.ghost ? (
+ dropSegment(overlayDrop!.t, overlayDrop!.len, h, overlayDrop!.ghost)
+ ) : (
+ <div
+ className="pointer-events-none absolute top-0.5 rounded-lg bg-[#0a84ff]/10 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.4)] transition-[left] duration-150 ease-out"
+ style={{
+ left: overlayDrop!.t * pps,
+ width: Math.max(10, overlayDrop!.len * pps - CLIP_GAP),
+ height: h,
+ }}
+ />
+ )
) : null;
// Only empty space gets the menu: a right-click on an item sits on a
@@ -1467,57 +1552,27 @@ export function Timeline() {
// stock drags carry their own shape since they aren't in the project yet.
let type: "video" | "audio" | "image" | undefined;
let duration = 0;
- // What the ghost paints: the source's frames, from wherever it lives.
- let ghost: DropGhost | undefined;
if (isLib) {
const lib = draggingLibrary();
type = lib?.type;
duration = lib?.duration ?? 0;
- if (lib && isClipMedia(lib.type)) {
- ghost = {
- url: libraryMediaUrl(lib.fileName, lib.residency),
- kind: lib.type,
- aspect: lib.width && lib.height ? lib.width / lib.height : undefined,
- };
- }
} else if (stockMusic) {
type = "audio";
duration = stockMusic.duration ?? 0;
} else if (stockVideo) {
type = "video";
duration = stockVideo.duration ?? 0;
- ghost = {
- url: stockVideo.url,
- kind: "video",
- aspect:
- stockVideo.width && stockVideo.height
- ? stockVideo.width / stockVideo.height
- : undefined,
- poster: stockVideo.thumb,
- };
} else if (still) {
type = "video";
duration = STILL_SECONDS;
- ghost = { url: still.url, kind: "image" };
} else {
const id = draggingAssetId();
const asset = id ? useEditor.getState().assets.find((a) => a.id === id) : null;
type = asset && asset.type !== "font" ? asset.type : undefined;
duration = asset?.type === "image" ? STILL_SECONDS : asset?.duration ?? 0;
- if (asset && !stickerOf(asset) && isClipMedia(asset.type)) {
- ghost =
- asset.type === "image"
- ? { url: asset.url, kind: "image" }
- : {
- url: asset.url,
- kind: "video",
- aspect: asset.width && asset.height ? asset.width / asset.height : undefined,
- thumbs: asset.thumbs,
- thumbStep: asset.thumbStep,
- poster: asset.thumbs?.[0],
- };
- }
}
+ // What the ghost paints: the source's frames, from wherever it lives.
+ const ghost = draggedVideo(e)?.ghost;
// A still rides the video tracks: reveal their guides and new-track rows.
setDropType(isClipMedia(type) ? "video" : type ?? null);
if (type === "audio") {
@@ -1540,7 +1595,7 @@ export function Timeline() {
const place = resolveDropTrack(e.clientX, e.clientY);
if (place.kind === "insert") {
setAssetDrop(null);
- setOverlayDrop({ target: place, t: dropTimeAt(e.clientX), len: duration });
+ setOverlayDrop({ target: place, t: dropTimeAt(e.clientX), len: duration, ghost });
return;
}
setOverlayDrop(null);
@@ -1548,8 +1603,12 @@ export function Timeline() {
// rippling later clips right, so the ghost sits where the segment will
// actually land — a box under the pointer that lands minutes away lies.
const cur = useEditor.getState();
- const { start } = rippleInsert(track0Clips(cur.clips), dropTimeAt(e.clientX), duration);
- setAssetDrop({ t: start, len: duration, ghost });
+ const { start, shifts } = rippleInsert(
+ track0Clips(cur.clips),
+ dropTimeAt(e.clientX),
+ duration
+ );
+ setAssetDrop({ t: start, len: duration, ghost, shifts });
}}
onDragLeave={(e) => {
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
@@ -2137,7 +2196,11 @@ export function Timeline() {
? laneDrag
: null
}
- parting={laneDrag?.kind === "overlayClip" && laneDrag.id !== span.clip.id}
+ parting={
+ (laneDrag?.kind === "overlayClip" && laneDrag.id !== span.clip.id) ||
+ videoDragActive
+ }
+ partAt={dropPartAt.get(span.clip.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
resolveTarget={resolveDropTrack}
@@ -2185,31 +2248,8 @@ export function Timeline() {
className="rounded-lg bg-[#0a84ff]/10 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.4),inset_0_2px_10px_rgba(10,60,140,0.08)]"
/>
)}
- {assetDrop && (
- // The dragged clip as a floating segment: its filmstrip fills it
- // and it rides above the row's clips (z-20), so a drag reads as a
- // placed segment sliding to its landing spot, not a hole to fill.
- <div
- className="tl-asset-drop-slot pointer-events-none absolute top-0.5 z-20 overflow-hidden rounded-lg bg-black opacity-90 shadow-2xl ring-[1.5px] ring-[#0a84ff]/70 transition-[left] duration-100 ease-out"
- style={{
- left: assetDrop.t * pps,
- width: Math.max(10, assetDrop.len * pps - CLIP_GAP),
- height: VIDEO_H - 4,
- }}
- >
- {assetDrop.ghost && (
- <DropGhostFilm
- ghost={assetDrop.ghost}
- w={Math.max(10, assetDrop.len * pps - CLIP_GAP)}
- h={VIDEO_H - 4}
- pps={pps}
- />
- )}
- <span className="absolute top-1 left-1 rounded-[5px] bg-black/65 px-1.5 py-px font-mono text-[10px] tabular-nums text-white">
- {assetDrop.len.toFixed(1)}s
- </span>
- </div>
- )}
+ {assetDrop &&
+ dropSegment(assetDrop.t, assetDrop.len, VIDEO_H - 4, assetDrop.ghost)}
{spans.map((span, i) => (
<ClipView
key={span.clip.id}
@@ -2218,7 +2258,10 @@ export function Timeline() {
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}
+ parting={
+ (laneDrag?.kind === "clip" && laneDrag.id !== span.clip.id) || videoDragActive
+ }
+ partAt={dropPartAt.get(span.clip.id)}
onDrag={setLaneDrag}
onSnap={setSnapX}
resolveTarget={resolveDropTrack}
@@ -3105,6 +3148,7 @@ function ClipView({
selected,
drag,
parting,
+ partAt,
onDrag,
onSnap,
resolveTarget,
@@ -3123,6 +3167,8 @@ function ClipView({
drag: LaneDrag | null;
/** Another track-0 clip is dragging: animate this one's parting shifts. */
parting: boolean;
+ /** The start this clip previews at while a hovering drop parts its row. */
+ partAt?: number;
onDrag: (d: LaneDrag | null) => void;
onSnap: (x: number | null) => void;
/** Which drop the given screen point is over (a track / an insert gap). */
@@ -3192,7 +3238,7 @@ function ClipView({
: parting && "transition-[left] duration-150 ease-out"
)}
style={{
- left: drag ? drag.ghostX : span.start * pps,
+ left: drag ? drag.ghostX : (partAt ?? span.start) * pps,
top: drag ? 2 + drag.ghostY : undefined,
width: Math.max(10, w - CLIP_GAP),
height: VIDEO_H - 4,
@@ -3918,6 +3964,7 @@ function OverlayClipView({
selected,
drag,
parting,
+ partAt,
onDrag,
onSnap,
resolveTarget,
@@ -3934,6 +3981,8 @@ function OverlayClipView({
drag: LaneDrag | null;
/** Another upper-layer clip is dragging: animate this one's parting shifts. */
parting: boolean;
+ /** The start this clip previews at while a hovering drop parts its row. */
+ partAt?: number;
onDrag: (d: LaneDrag | null) => void;
onSnap: (x: number | null) => void;
resolveTarget: (clientX: number, clientY: number) => TrackTarget;
@@ -4001,7 +4050,7 @@ function OverlayClipView({
: parting && "transition-[left] duration-150 ease-out"
)}
style={{
- left: drag ? drag.ghostX : clip.start * pps,
+ left: drag ? drag.ghostX : (partAt ?? clip.start) * pps,
top: drag ? 2 + drag.ghostY : undefined,
width: Math.max(10, w - CLIP_GAP),
height: OVERLAY_H - 4,
diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.ts
index 6e8b74a3..c0f853e8 100644
--- a/site/src/cut/lib/laneTracks.ts
+++ b/site/src/cut/lib/laneTracks.ts
@@ -98,6 +98,11 @@ interface LaneAdapter<T> {
lanePatch?(raw: T, lane: number): Patch<T>;
/** The media behind the item, so dragging it can feed reference drop zones. */
assetOf?(s: S, raw: T): MediaAsset | undefined;
+ /** A lifted item's slot closes behind it: while one drags, same-lane items
+ * past its old spot rest slid left by its length, so the run heals the
+ * moment the item leaves. Video tracks set this; free-form lanes (audio,
+ * titles, cues) hold every resting spot. */
+ closesGap?: boolean;
/** After a committed move (e.g. keep cues sorted). */
onMoved?(): void;
/** After a committed move, shift companions that ride along — a grouped
@@ -137,6 +142,7 @@ const clipAdapter: LaneAdapter<VideoClip> = {
}),
leftFloor: (c) => Math.max(0, c.start - c.in / speedOf(c)),
maxLen: videoMaxLen,
+ closesGap: true,
assetOf: (s, c) => s.assets.find((x) => x.id === c.assetId),
onMoved: () => useEditor.getState().sortClips(),
};
@@ -205,6 +211,7 @@ const overlayClipAdapter: LaneAdapter<VideoClip> = {
}),
leftFloor: (c) => Math.max(0, c.start - c.in / speedOf(c)),
maxLen: videoMaxLen,
+ closesGap: true,
assetOf: (s, c) => s.assets.find((x) => x.id === c.assetId),
};
@@ -413,6 +420,14 @@ export function startLaneMove<V = unknown>(
.raws(s)
.filter((r) => ad.view(r).id !== id)
.map((r) => ({ raw: r, view: ad.view(r) }));
+ // Where a neighbor rests while the drag is live. On a gap-closing lane the
+ // lifted clip's slot heals under it: same-lane neighbors past its old spot
+ // rest slid left by its length, and the parting below lays the lane out
+ // from these closed spots.
+ const restAt = (x: (typeof rest)[number]) =>
+ ad.closesGap && x.view.lane === self.lane && x.view.start > start0 + 1e-9
+ ? x.view.start - len
+ : x.view.start;
const usedLanes = laneOrder(kind, s, [...rest.map((x) => x.view.lane), self.lane]);
const targets = snapTargets(s, kind, id);
const tol = SNAP_PX / ui.pps;
@@ -478,7 +493,8 @@ export function startLaneMove<V = unknown>(
const target = ui.vertical.resolve(ev);
if (!ui.vertical.isHome(target)) {
awayTarget = target;
- restRestore();
+ // The hole the clip left stays closed while it hovers other tracks.
+ applyMoves(restAt);
ui.onSnap(null);
ui.vertical.preview(target, ds, len);
ui.onDrag({
@@ -543,6 +559,9 @@ export function startLaneMove<V = unknown>(
// neighbor before it by that neighbor's declared transition, and only
// pushes the run after it once the overlap into its first item exceeds the
// item's own declared transition.
+ // Order comes from the original midpoints, so a lifted clip keeps its
+ // spot until the pointer truly crosses a neighbor's middle; the runs
+ // themselves sit at their resting spots (closed on gap-closing lanes).
const others = rest
.filter((x) => x.view.lane === lane)
.sort((a, b) => a.view.start - b.view.start);
@@ -552,19 +571,19 @@ export function startLaneMove<V = unknown>(
const clampFloor = prev
? Math.max(
0,
- ...before.slice(0, -1).map((b) => b.view.start + b.view.len),
- prev.view.start + prev.view.len
+ ...before.slice(0, -1).map((b) => restAt(b) + b.view.len),
+ restAt(prev) + prev.view.len
)
: 0;
const clamped = Math.max(start, clampFloor);
if (clamped !== start) guide = null;
slotStart = clamped;
const delta = after.length
- ? Math.max(0, clamped + len - after[0].view.start)
+ ? Math.max(0, clamped + len - restAt(after[0]))
: 0;
const pushed = new Set(after.map((x) => x.view.id));
ui.onSnap(guide);
- applyMoves((x) => (pushed.has(x.view.id) ? x.view.start + delta : x.view.start));
+ applyMoves((x) => (pushed.has(x.view.id) ? restAt(x) + delta : restAt(x)));
ui.onDrag({ kind, id, targetRow, ghostX: ds * ui.pps, ghostY, slotStart: clamped, len });
},
onUp: (_dx, _dy, moved) => {
@@ -578,6 +597,9 @@ export function startLaneMove<V = unknown>(
return;
}
if (ui.vertical && awayTarget !== null && !ui.vertical.isHome(awayTarget)) {
+ // The cross-track commit closes the source gap itself, from resting
+ // starts — undo the live closure first or the run slides twice.
+ restRestore();
ui.vertical.commit(id, awayTarget, ds);
return;
}
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.ts
index 56ffe2f3..c3ecad3f 100644
--- a/site/src/cut/lib/store.ts
+++ b/site/src/cut/lib/store.ts
@@ -2654,10 +2654,21 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
if (!src) return;
// No checkpoint here: the lane coordinator's drag gesture already pushed
// one at pointer-down, so the whole move is a single undo step.
- const onTrack0 = src.track === 0;
+ if (place.kind === "track" && place.track === src.track) {
+ return; // a same-track move commits through the lane coordinator
+ }
+
+ // The clip leaves its track, so the hole it leaves closes behind it:
+ // the source row's later clips slide left by its length. Matching by id
+ // keeps the closure correct through an insert's track renumbering.
+ const srcLen = clipLen(src);
+ const closing: [string, number][] = get()
+ .clips.filter(
+ (c) => c.track === src.track && c.id !== id && c.start > src.start + 1e-9
+ )
+ .map((c) => [c.id, Math.max(0, c.start - srcLen)]);
if (place.kind === "track" && place.track === 0) {
- if (onTrack0) return; // a same-track move commits through the lane coordinator
// Drop a layer clip down onto track 0: insert at the pointer, rippling
// later clips right — the same landing a drag along the row gives.
const { start: at, shifts } = rippleInsert(
@@ -2665,7 +2676,7 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
Math.max(0, start),
clipLen(src)
);
- const move = new Map(shifts.map((sh) => [sh.id, sh.start]));
+ const move = new Map([...shifts.map((sh) => [sh.id, sh.start] as const), ...closing]);
set((st) => {
const clips = st.clips
.map((c) =>
@@ -2697,22 +2708,29 @@ export const useEditor = create<EditorState>((baseSet, get, api) => {
clipLen(src)
)
: { start: Math.max(0, start), shifts: [] as { id: string; start: number }[] };
- const move = new Map(landing.shifts.map((sh) => [sh.id, sh.start]));
+ const move = new Map([
+ ...landing.shifts.map((sh) => [sh.id, sh.start] as const),
+ ...closing,
+ ]);
set((st) => {
// Inserting a new track opens the slot by renumbering the others; the
// moved clip itself is excluded from the shift, then placed at `track`.
const shifted =
place.kind === "insert" ? openInsertSlot(st.clips, place.level, id) : st.clips;
+ const clips = shifted
+ .map((c) =>
+ c.id === id
+ ? { ...c, track, start: landing.start }
+ : move.has(c.id)
+ ? { ...c, start: move.get(c.id)! }
+ : c
+ )
+ .sort((a, b) => a.start - b.start);
return {
- clips: shifted
- .map((c) =>
- c.id === id
- ? { ...c, track, start: landing.start }
- : move.has(c.id)
- ? { ...c, start: move.get(c.id)! }
- : c
- )
- .sort((a, b) => a.start - b.start),
+ clips,
+ // A clip lifted off track 0 shifts the spine, and its cuts carry
+ // the transitions with them.
+ transitions: reanchorTransitions(st.clips, clips, st.transitions),
...sole({ kind: "clip", id }),
};
});