Skip to content

Open source CapCut alternative.

TypeScript

fix(site): a timeline drag offers only the rows it can land on

David Le9c1212a6442c
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsx
index 187c650a..5ca46ccc 100644
--- a/site/src/cut/components/Timeline.tsx
+++ b/site/src/cut/components/Timeline.tsx
@@ -2130,9 +2130,9 @@ export function Timeline() {
height:
Math.max(
overlayLanes.count,
- // An in-flight element drag shows the whole landing area,
- // the would-be new row below included.
- laneDrag?.kind === "overlay" ? overlayLanes.count + 1 : 0,
+ // An in-flight element drag shows its whole landing area —
+ // only the rows it can actually reach.
+ laneDrag?.kind === "overlay" ? laneDrag.maxRow + 1 : 0,
// A panel drag over an empty band opens the first row for
// its landing preview.
elementDrop !== null ? elementDrop.row + 1 : 0
@@ -2245,7 +2245,7 @@ export function Timeline() {
/>
)}
{laneDrag?.kind === "overlay" &&
- Array.from({ length: overlayLanes.count + 1 }, (_, r) => (
+ Array.from({ length: laneDrag.maxRow + 1 }, (_, r) => (
<div
key={r}
className={cn(
@@ -2532,9 +2532,9 @@ export function Timeline() {
height:
Math.max(
audioLanes.count,
- // An in-flight audio drag shows the whole landing area,
- // the would-be new track included.
- laneDrag?.kind === "audio" ? audioLanes.count + 1 : 0,
+ // An in-flight audio drag shows its whole landing area —
+ // only the rows it can actually reach.
+ laneDrag?.kind === "audio" ? laneDrag.maxRow + 1 : 0,
(audioDrop?.row ?? -1) + 1
) * AUDIO_H,
}}
@@ -2554,7 +2554,7 @@ export function Timeline() {
</Fragment>
))}
{laneDrag?.kind === "audio" &&
- Array.from({ length: audioLanes.count + 1 }, (_, r) => (
+ Array.from({ length: laneDrag.maxRow + 1 }, (_, r) => (
<div
key={r}
className={cn(
diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.ts
index faa6d4ba..fb3aad2c 100644
--- a/site/src/cut/lib/laneTracks.ts
+++ b/site/src/cut/lib/laneTracks.ts
@@ -327,6 +327,10 @@ export interface LaneDrag {
/** Hovered display row. One past the end opens a new row below; -1 opens
* one above the top, for a stack whose order is z-order. */
targetRow: number;
+ /** The rows this drag can land on, inclusive — the band paints exactly
+ * these and nothing else. */
+ minRow: number;
+ maxRow: number;
ghostX: number; // ghost left in px — follows the pointer
ghostY: number; // ghost vertical offset in px from its resting row — follows the pointer
slotStart: number; // resolved landing start, seconds
@@ -435,6 +439,20 @@ export function startLaneMove<V = unknown>(
.filter((x) => x.view.lane === self.lane)
.reduce((m, x) => Math.max(m, restAt(x) + x.view.len), 0);
const usedLanes = laneOrder(kind, s, [...rest.map((x) => x.view.lane), self.lane]);
+ // The rows this drag can reach. A row past either end opens a brand-new
+ // track, and from an outermost row an item alone there has nothing to open
+ // on its side: the row it left collapses behind it, so the fresh one
+ // renumbers straight back to the picture already on screen. Single-lane
+ // kinds stay on the row they were grabbed from.
+ const alone = !rest.some((x) => x.view.lane === self.lane);
+ const minRow = ad.multiLane
+ ? ui.topInsert && !(alone && ui.homeRow === 0)
+ ? -1
+ : 0
+ : ui.homeRow;
+ const maxRow = ad.multiLane
+ ? ui.laneCount - (alone && ui.homeRow === ui.laneCount - 1 ? 1 : 0)
+ : ui.homeRow;
const targets = snapTargets(s, kind, id);
const tol = SNAP_PX / ui.pps;
// Dragging a media-backed item can also hand its asset to a reference drop
@@ -521,6 +539,8 @@ export function startLaneMove<V = unknown>(
kind,
id,
targetRow: ui.homeRow,
+ minRow,
+ maxRow,
ghostX: ds * ui.pps,
ghostY,
slotStart: ds,
@@ -533,13 +553,8 @@ export function startLaneMove<V = unknown>(
ui.vertical.preview(null, 0, 0);
}
- // Vertical drag retracks the item; one row past the end opens a new one.
- targetRow = ad.multiLane
- ? Math.min(
- ui.laneCount,
- Math.max(ui.topInsert ? -1 : 0, ui.homeRow + Math.round(dy / ui.rowH))
- )
- : ui.homeRow;
+ // Vertical drag retracks the item, across the rows it can reach.
+ targetRow = Math.min(maxRow, Math.max(minRow, ui.homeRow + Math.round(dy / ui.rowH)));
// Which lane to part/collide on: multi-lane rows are display indexes
// into the compacted used-lane list (a row past the end is a brand-new
// lane with no neighbors); single-lane kinds stay on their own lane —
@@ -604,7 +619,17 @@ export function startLaneMove<V = unknown>(
const pushed = new Set(after.map((x) => x.view.id));
ui.onSnap(guide);
applyMoves((x) => (pushed.has(x.view.id) ? restAt(x) + delta : restAt(x)), clamped);
- ui.onDrag({ kind, id, targetRow, ghostX: ds * ui.pps, ghostY, slotStart: clamped, len });
+ ui.onDrag({
+ kind,
+ id,
+ targetRow,
+ minRow,
+ maxRow,
+ ghostX: ds * ui.pps,
+ ghostY,
+ slotStart: clamped,
+ len,
+ });
},
onUp: (_dx, _dy, moved) => {
ui.vertical?.setActive?.(false);