diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-31 22:38:56 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-31 22:38:56 +0200 |
| commit | 0488a6be455c225535414fd651c838c355a9d3bd (patch) | |
| tree | 54bb89b6167b5205b810e15a2b34d88f2644eb69 /apps/web/src/lib/timeline/placement/resolve.ts | |
| parent | 0f5dca4f12d926ec0015116e85ec1129a6891f40 (diff) | |
| download | opencut-0488a6be455c225535414fd651c838c355a9d3bd.tar.gz | |
fix: normalize vertical drag direction in preferIndex placement
Diffstat (limited to 'apps/web/src/lib/timeline/placement/resolve.ts')
| -rw-r--r-- | apps/web/src/lib/timeline/placement/resolve.ts | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/apps/web/src/lib/timeline/placement/resolve.ts b/apps/web/src/lib/timeline/placement/resolve.ts index 235c789a..35718250 100644 --- a/apps/web/src/lib/timeline/placement/resolve.ts +++ b/apps/web/src/lib/timeline/placement/resolve.ts @@ -44,9 +44,7 @@ function buildExistingTrackResult({ trackId: track.id, trackIndex, trackType: track.type, - ...(adjustedStartTime !== requestedStartTime - ? { adjustedStartTime } - : {}), + ...(adjustedStartTime !== requestedStartTime ? { adjustedStartTime } : {}), }; } @@ -114,6 +112,24 @@ function resolveAlwaysNewTrack({ }); } +function getInsertDirection({ + hoverDirection, + verticalDragDirection, +}: { + hoverDirection: "above" | "below"; + verticalDragDirection?: "up" | "down" | null; +}): "above" | "below" { + if (verticalDragDirection === "up") { + return "above"; + } + + if (verticalDragDirection === "down") { + return "below"; + } + + return hoverDirection; +} + export function resolveTrackPlacement({ tracks, ...placement @@ -127,7 +143,9 @@ export function resolveTrackPlacement({ const { timeSpans, strategy } = placement; if (strategy.type === "explicit") { - const trackIndex = tracks.findIndex((track) => track.id === strategy.trackId); + const trackIndex = tracks.findIndex( + (track) => track.id === strategy.trackId, + ); if (trackIndex < 0) { return null; } @@ -182,15 +200,16 @@ export function resolveTrackPlacement({ }); } - const insertDirection = - !isPreferredTrackCompatible && strategy.verticalDragDirection - ? strategy.verticalDragDirection - : strategy.hoverDirection; const { insertIndex, insertPosition } = resolvePreferredNewTrackPlacement({ tracks, trackType, preferredIndex: strategy.trackIndex, - direction: insertDirection, + direction: getInsertDirection({ + hoverDirection: strategy.hoverDirection, + verticalDragDirection: !isPreferredTrackCompatible + ? strategy.verticalDragDirection + : null, + }), }); return buildNewTrackResult({ trackType, |
