diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-02-08 01:51:25 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-02-08 01:51:25 +0100 |
| commit | 9b5fd6eb077a3fb2380f42414b65405030a01fcd (patch) | |
| tree | 91d56e1c71e9a876afb1ae39fe4644ed8d5accee /apps/web/src/lib/timeline/drop-utils.ts | |
| parent | 00cf7f6ab7b35616290cfeab06256a14f6d4beba (diff) | |
| download | opencut-9b5fd6eb077a3fb2380f42414b65405030a01fcd.tar.gz | |
feat: ensure elements on main track starts at 0
Diffstat (limited to 'apps/web/src/lib/timeline/drop-utils.ts')
| -rw-r--r-- | apps/web/src/lib/timeline/drop-utils.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/apps/web/src/lib/timeline/drop-utils.ts b/apps/web/src/lib/timeline/drop-utils.ts index 8c22194a..9182892f 100644 --- a/apps/web/src/lib/timeline/drop-utils.ts +++ b/apps/web/src/lib/timeline/drop-utils.ts @@ -2,7 +2,7 @@ import type { TimelineTrack, ElementType } from "@/types/timeline"; import { TRACK_HEIGHTS, TRACK_GAP } from "@/constants/timeline-constants"; import { wouldElementOverlap } from "./element-utils"; import type { ComputeDropTargetParams, DropTarget } from "@/types/timeline"; -import { isMainTrack } from "./track-utils"; +import { isMainTrack, enforceMainTrackStart } from "./track-utils"; function getTrackAtY({ mouseY, @@ -185,11 +185,21 @@ export function computeDropTarget({ }); if (isTrackCompatible && !hasOverlap) { + const targetTrack = tracks[trackIndex]; + // safe: snap to 0 only happens when element becomes the new earliest, + // meaning the space before the current earliest is empty + const adjustedXPosition = enforceMainTrackStart({ + tracks, + targetTrackId: targetTrack.id, + requestedStartTime: xPosition, + excludeElementId, + }); + return { trackIndex, isNewTrack: false, insertPosition: null, - xPosition, + xPosition: adjustedXPosition, }; } |
