|
7 | 7 | type DragPreviewContext, |
8 | 8 | } from "./timelineClipDragPreview"; |
9 | 9 | import type { DraggedClipState } from "./timelineClipDragTypes"; |
10 | | -import { commitDraggedClipMove } from "./timelineClipDragCommit"; |
| 10 | +import { commitDraggedClipMove, persistMoveEdits } from "./timelineClipDragCommit"; |
11 | 11 | import { LANE_H, RULER_H, TRACKS_TOP_PAD, TRACK_H } from "./timelineLayout"; |
12 | 12 |
|
13 | 13 | // ───────────────────────────────────────────────────────────────────────────── |
@@ -466,3 +466,72 @@ describe("computeDragPreview — the ghost start is the committed start", () => |
466 | 466 | } |
467 | 467 | }); |
468 | 468 | }); |
| 469 | + |
| 470 | +describe("a nested clip's drop stops at its host's start in the preview", () => { |
| 471 | + // Host at 2 s: the clip may not start before 2 unless it was authored there. |
| 472 | + const logo: TimelineElement = { ...clip("logo", 0, 5, 5, 0, "div"), parentCompositionStart: 2 }; |
| 473 | + const saved = async (element: TimelineElement, start: number) => { |
| 474 | + const updateElement = vi.fn(); |
| 475 | + await persistMoveEdits([{ element, updates: { start, track: element.track } }], { |
| 476 | + elements: [element], |
| 477 | + trackOrder: [0, 1, 2], |
| 478 | + updateElement, |
| 479 | + onMoveElements: vi.fn(async () => {}), |
| 480 | + }); |
| 481 | + return updateElement.mock.calls[0]?.[1]?.start; |
| 482 | + }; |
| 483 | + |
| 484 | + it("holds a drop that snapping would put before the host, and saves the same start", async () => { |
| 485 | + const { drag, clientX, clientY } = horizontalDrag(logo, 0.5, -3.9); |
| 486 | + const next = computeDragPreview(drag, clientX, clientY, { |
| 487 | + ...ctx(undefined, [logo]), |
| 488 | + buildSnapTargets: () => [{ time: 1.9, type: "beat" }], |
| 489 | + }); |
| 490 | + expect(next.previewStart).toBe(2); |
| 491 | + expect(next.snapTime).toBeNull(); |
| 492 | + expect(await saved(logo, next.previewStart)).toBe(2); |
| 493 | + }); |
| 494 | + |
| 495 | + it("snaps from the floor, so an edge just past the host's start still catches", () => { |
| 496 | + const { drag, clientX, clientY } = horizontalDrag(logo, 0.5, -3.9); |
| 497 | + const next = computeDragPreview(drag, clientX, clientY, { |
| 498 | + ...ctx(undefined, [logo]), |
| 499 | + buildSnapTargets: () => [{ time: 2.1, type: "beat" }], |
| 500 | + }); |
| 501 | + expect(next).toMatchObject({ previewStart: 2.1, snapTime: 2.1 }); |
| 502 | + }); |
| 503 | + |
| 504 | + it("keeps a mixed group's spacing when the nested member meets its floor", () => { |
| 505 | + // Grab the top-level member: only the group clamp knows the nested one's floor. |
| 506 | + const outro = clip("outro", 1, 8, 2, 0, "div"); |
| 507 | + const { drag, clientX, clientY } = horizontalDrag(outro, 1.5, -7); |
| 508 | + const next = computeDragPreview(drag, clientX, clientY, { |
| 509 | + ...ctx(undefined, [logo, outro]), |
| 510 | + selectedKeys: new Set(["logo", "outro"]), |
| 511 | + }); |
| 512 | + expect(next.previewStart).toBe(5); |
| 513 | + }); |
| 514 | + |
| 515 | + it("leaves a clip authored before its host's start in place when grabbed", async () => { |
| 516 | + const early: TimelineElement = { ...logo, id: "early", key: "early", domId: "early", start: 1 }; |
| 517 | + const { drag, clientX, clientY } = horizontalDrag(early, 0.5, 0); |
| 518 | + expect(computeDragPreview(drag, clientX, clientY, ctx(undefined, [early])).previewStart).toBe( |
| 519 | + 1, |
| 520 | + ); |
| 521 | + const trim = computeResizePreview( |
| 522 | + { |
| 523 | + element: early, |
| 524 | + edge: "start", |
| 525 | + originClientX: 0, |
| 526 | + previewStart: 1, |
| 527 | + previewDuration: 5, |
| 528 | + started: true, |
| 529 | + pointerId: 0, |
| 530 | + }, |
| 531 | + 0, |
| 532 | + { scroll: fakeScroll(), pps: PPS, buildSnapTargets: () => [] }, |
| 533 | + ); |
| 534 | + expect(trim).toMatchObject({ previewStart: 1, previewDuration: 5 }); |
| 535 | + expect(await saved(early, 1)).toBe(1); |
| 536 | + }); |
| 537 | +}); |
0 commit comments