From 0488a6be455c225535414fd651c838c355a9d3bd Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Tue, 31 Mar 2026 22:38:56 +0200 Subject: fix: normalize vertical drag direction in preferIndex placement --- apps/web/src/lib/timeline/placement/resolve.ts | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'apps/web/src/lib/timeline/placement/resolve.ts') 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, -- cgit v1.3.1