From 060a7bab922c1fdd038ae3ebb8fb5e8e719d0b60 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Tue, 25 Nov 2025 17:24:35 -0700 Subject: [PATCH] timeline updates --- .../video-editor/timeline/TimelineEditor.tsx | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx index 13a07ce..8b62801 100644 --- a/src/components/video-editor/timeline/TimelineEditor.tsx +++ b/src/components/video-editor/timeline/TimelineEditor.tsx @@ -413,34 +413,31 @@ export default function TimelineEditor({ return; } - const defaultDuration = Math.min( - Math.max(3000, safeMinDurationMs), - totalMs, - ); + const defaultDuration = Math.min(1000, totalMs); if (defaultDuration <= 0) { return; } - let startPos = 0; + // Always place zoom at playhead + const startPos = Math.max(0, Math.min(currentTimeMs, totalMs)); + // Find the next zoom region after the playhead const sorted = [...zoomRegions].sort((a, b) => a.startMs - b.startMs); + const nextRegion = sorted.find(region => region.startMs > startPos); + const gapToNext = nextRegion ? nextRegion.startMs - startPos : totalMs - startPos; - for (const region of sorted) { - if (startPos + defaultDuration <= region.startMs) { - break; - } - startPos = Math.max(startPos, region.endMs); - } - - if (startPos + defaultDuration > totalMs) { - toast.error("No space available", { - description: "Remove or resize existing zoom regions to add more.", + // Check if playhead is inside any zoom region + const isOverlapping = sorted.some(region => startPos >= region.startMs && startPos < region.endMs); + if (isOverlapping || gapToNext <= 0) { + toast.error("Cannot place zoom here", { + description: "Zoom already exists at this location or not enough space available.", }); return; } - onZoomAdded({ start: startPos, end: startPos + defaultDuration }); - }, [videoDuration, totalMs, timelineScale.defaultItemDurationMs, safeMinDurationMs, zoomRegions, onZoomAdded]); + const actualDuration = Math.min(1000, gapToNext); + onZoomAdded({ start: startPos, end: startPos + actualDuration }); + }, [videoDuration, totalMs, currentTimeMs, zoomRegions, onZoomAdded]); const clampedRange = useMemo(() => { if (totalMs === 0) {