Skip to content

Commit 9730975

Browse files
committed
fix(studio): a row move restacks only the dragged clip and a move down never hides it
Selected clips that only shifted in time keep their z-index. A move down stops at the clips on lower rows it paints over, instead of dropping under them when z-index 0 cannot get it behind the clip above.
1 parent 400bbe1 commit 9730975

4 files changed

Lines changed: 55 additions & 11 deletions

File tree

‎packages/studio/src/player/components/timelineClipDragCommit.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,28 @@ describe("commitDraggedClipMove", () => {
588588
expectZLiftedToSix(onStackingPatches);
589589
});
590590

591+
it("a multi-selection lane move restacks only the dragged clip", async () => {
592+
// a moves up from row 2 to row 1 over c; the selected scene keeps its row, so it keeps its z.
593+
const elements = [
594+
el("scene", 0, 0, 10),
595+
el("b", 1, 5, 5),
596+
el("a", 2, 0, 4),
597+
el("c", 3, 0, 4),
598+
];
599+
const z: Record<string, number> = { scene: 0, b: 2, a: 1, c: 3 };
600+
const onStackingPatches = vi.fn();
601+
runClipMove(drag(elements[2], { previewStart: 0, previewTrack: 1 }), {
602+
elements,
603+
trackOrder: [0, 1, 2, 3],
604+
selectedKeys: new Set(["a", "scene"]),
605+
readZIndex: (e) => z[e.key ?? e.id] ?? 0,
606+
onStackingPatches,
607+
});
608+
await flushMicrotasks();
609+
expect(onStackingPatches).toHaveBeenCalledTimes(1);
610+
expect(onStackingPatches.mock.calls[0][0]).toEqual([{ key: "a", zIndex: 4 }]);
611+
});
612+
591613
it("partial z-sync deps (no readZIndex) → move persists but no stacking call", async () => {
592614
const elements = [el("a", 1, 0, 10), el("b", 0, 0, 10)];
593615
// onStackingPatches present but readZIndex absent → syncStackingForEdit needs

‎packages/studio/src/player/components/timelineClipDragCommit.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ export function commitDraggedClipMove(drag: DraggedClipState, deps: DragCommitDe
337337
if (multi?.keys.has(keyOf(e))) return { ...e, start: multi.movedStart(e) };
338338
return e;
339339
});
340-
const multiKeys = multi ? multi.keys : null;
341340
if (!isVertical || !deps.readZIndex || !deps.onStackingPatches) {
342341
void refreshAfterDurableLaneMove(
343342
persistMoveEdits(edits, deps, coalesceKey, "lane-reorder"),
@@ -354,7 +353,6 @@ export function commitDraggedClipMove(drag: DraggedClipState, deps: DragCommitDe
354353
dragKey,
355354
drag.element.track,
356355
drag.previewTrack,
357-
multiKeys,
358356
deps,
359357
coalesceKey,
360358
),
@@ -472,7 +470,6 @@ function commitTrackInsert(
472470
dragKey,
473471
drag.element.track,
474472
drag.insertRow!,
475-
multi ? multi.keys : null,
476473
deps,
477474
coalesceKey,
478475
),
@@ -542,7 +539,6 @@ function syncStackingForEdit(
542539
dragKey: string,
543540
currentLane: number,
544541
aimedLane: number,
545-
multiKeys: ReadonlySet<string> | null,
546542
deps: DragCommitDeps,
547543
coalesceKey?: string,
548544
): Promise<void> {
@@ -567,12 +563,10 @@ function syncStackingForEdit(
567563
stackingContextId: el.stackingContextId ?? null,
568564
}));
569565

570-
const editedKeys = [dragKey];
571-
if (multiKeys) for (const k of multiKeys) if (k !== dragKey) editedKeys.push(k);
572-
566+
// Only the dragged clip changes row; selected clips that shifted in time keep their z.
573567
const patches = computeStackingPatches(
574568
stackingEls,
575-
editedKeys,
569+
[dragKey],
576570
aimedLane < currentLane ? "up" : "down",
577571
);
578572
if (patches.length === 0) return Promise.resolve();

‎packages/studio/src/player/components/timelineStackingSync.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,26 @@ describe("computeStackingPatches — only the moved clip changes", () => {
262262
expect(patchMap(elements, ["v"], "down")).toEqual({});
263263
});
264264

265+
it("moved down never goes under a clip on a lower row it paints over now", () => {
266+
// v cannot get under r (z0, earlier in the file); dropping it to 0 would hide it under w.
267+
const elements = [
268+
el("r", 0, 0, 10, 0, false, 0),
269+
el("v", 1, 0, 10, 2, false, 1),
270+
el("w", 2, 0, 10, 1, false, 2),
271+
];
272+
expect(patchMap(elements, ["v"], "down")).toEqual({});
273+
});
274+
275+
it("moved down sinks only as far as the clips on lower rows allow", () => {
276+
const elements = [el("s", 0, 0, 10, 5), el("v", 1, 0, 10, 9), el("w", 2, 0, 10, 7)];
277+
expect(patchMap(elements, ["v"], "down")).toEqual({ v: 8 });
278+
});
279+
280+
it("moved down with equal z: the clip above, later in the file, already paints over it", () => {
281+
const elements = [el("v", 1, 0, 10, 3, false, 0), el("r", 0, 0, 10, 3, false, 1)];
282+
expect(patchMap(elements, ["v"], "down")).toEqual({});
283+
});
284+
265285
it("#2198: an untouched pair keeps its order because neighbours never move", () => {
266286
// e overlaps n [5,10); n overlaps m [12,15); e does not overlap m.
267287
const elements = [

‎packages/studio/src/player/components/timelineStackingSync.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,20 @@ function raisedZ(clip: StackingElement, overlapping: StackingElement[]): number
137137
return Math.max(...below.map((o) => o.zIndex)) + 1;
138138
}
139139

140-
/** Moved down: one below the lowest clip it now sits under, never under z 0 (a negative z can paint behind the
141-
* composition's own background), or null when it already paints under them all or cannot go lower. */
140+
/** Moved down: one below the lowest clip it now sits under, but never under z 0 (a negative z can paint behind the
141+
* composition's own background) and never under a clip on a lower row it paints over now, so the move cannot hide it.
142+
* Null when it already paints under them all or cannot go lower. */
142143
function loweredZ(clip: StackingElement, overlapping: StackingElement[]): number | null {
143144
const above = overlapping.filter((o) => laneIsAbove(o, clip));
144145
if (above.every((o) => paintsAbove(o, clip))) return null;
145-
const z = Math.max(0, Math.min(...above.map((o) => o.zIndex)) - 1);
146+
const keepOver = overlapping.filter((o) => laneIsAbove(clip, o) && paintsAbove(clip, o));
147+
const floor = Math.max(
148+
0,
149+
...keepOver.map((o) =>
150+
paintsAbove({ ...clip, zIndex: o.zIndex }, o) ? o.zIndex : o.zIndex + 1,
151+
),
152+
);
153+
const z = Math.max(floor, Math.min(...above.map((o) => o.zIndex)) - 1);
146154
return z < clip.zIndex ? z : null;
147155
}
148156

0 commit comments

Comments
 (0)