Create polished demo videos without editing skills. Mac/Windows/Linux
clean up clip-first timeline editing
webadderallb4a0861883f3
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex 6c93876e..2749de16 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -147,7 +147,6 @@ import {DEFAULT_CROP_REGION,DEFAULT_CURSOR_STYLE,DEFAULT_FIGURE_DATA,- DEFAULT_PLAYBACK_SPEED,DEFAULT_WEBCAM_OVERLAY,DEFAULT_WEBCAM_TIME_OFFSET_MS,DEFAULT_ZOOM_IN_DURATION_MS,@@ -159,10 +158,12 @@ import {extendAutoFullTrackClip,type FigureData,getClipSourceEndMs,+ mapSourceTimeToTimelineTime as resolveSourceTimeToTimelineTime,+ mapTimelineTimeToSourceTime as resolveTimelineTimeToSourceTime,type Padding,- type PlaybackSpeed,type SpeedRegion,type TrimRegion,+ trimsToClips,type WebcamOverlaySettings,type ZoomDepth,type ZoomFocus,@@ -184,9 +185,7 @@ type EditorHistorySnapshot = {audioRegions: AudioRegion[];autoCaptions: CaptionCue[];selectedZoomId: string | null;- selectedTrimId: string | null;selectedClipId: string | null;- selectedSpeedId: string | null;selectedAnnotationId: string | null;selectedAudioId: string | null;};@@ -653,11 +652,9 @@ export default function VideoEditor() {const [cursorTelemetrySourcePath, setCursorTelemetrySourcePath] = useState<string | null>(null);const [selectedZoomId, setSelectedZoomId] = useState<string | null>(null);const [trimRegions, setTrimRegions] = useState<TrimRegion[]>([]);- const [selectedTrimId, setSelectedTrimId] = useState<string | null>(null);const [clipRegions, setClipRegions] = useState<ClipRegion[]>([]);const [selectedClipId, setSelectedClipId] = useState<string | null>(null);const [speedRegions, setSpeedRegions] = useState<SpeedRegion[]>([]);- const [selectedSpeedId, setSelectedSpeedId] = useState<string | null>(null);const [annotationRegions, setAnnotationRegions] = useState<AnnotationRegion[]>([]);const [selectedAnnotationId, setSelectedAnnotationId] = useState<string | null>(null);const [audioRegions, setAudioRegions] = useState<AudioRegion[]>([]);@@ -731,9 +728,7 @@ export default function VideoEditor() {const projectBrowserFallbackTriggerRef = useRef<HTMLButtonElement | null>(null);const projectNameInputRef = useRef<HTMLInputElement | null>(null);const nextZoomIdRef = useRef(1);- const nextTrimIdRef = useRef(1);const nextClipIdRef = useRef(1);- const nextSpeedIdRef = useRef(1);const nextAudioIdRef = useRef(1);const { shortcuts, isMac } = useShortcuts();@@ -1567,9 +1562,7 @@ export default function VideoEditor() {audioRegions,autoCaptions,selectedZoomId,- selectedTrimId,selectedClipId,- selectedSpeedId,selectedAnnotationId,selectedAudioId,};@@ -1581,9 +1574,7 @@ export default function VideoEditor() {audioRegions,autoCaptions,selectedZoomId,- selectedTrimId,selectedClipId,- selectedSpeedId,selectedAnnotationId,selectedAudioId,]);@@ -1599,9 +1590,7 @@ export default function VideoEditor() {setAudioRegions(cloned.audioRegions);setAutoCaptions(cloned.autoCaptions);setSelectedZoomId(cloned.selectedZoomId);- setSelectedTrimId(cloned.selectedTrimId);setSelectedClipId(cloned.selectedClipId);- setSelectedSpeedId(cloned.selectedSpeedId);setSelectedAnnotationId(cloned.selectedAnnotationId);setSelectedAudioId(cloned.selectedAudioId);@@ -1613,10 +1602,6 @@ export default function VideoEditor() {"clip",cloned.clipRegions.map((region) => region.id),);- nextSpeedIdRef.current = deriveNextId(- "speed",- cloned.speedRegions.map((region) => region.id),- );nextAnnotationIdRef.current = deriveNextId("annotation",cloned.annotationRegions.map((region) => region.id),@@ -1748,9 +1733,7 @@ export default function VideoEditor() {setGifSizePreset(normalizedEditor.gifSizePreset);setSelectedZoomId(null);- setSelectedTrimId(null);setSelectedClipId(null);- setSelectedSpeedId(null);setSelectedAnnotationId(null);setSelectedAudioId(null);@@ -1758,18 +1741,10 @@ export default function VideoEditor() {"zoom",normalizedEditor.zoomRegions.map((region) => region.id),);- nextTrimIdRef.current = deriveNextId(- "trim",- normalizedEditor.trimRegions.map((region) => region.id),- );nextClipIdRef.current = deriveNextId("clip",normalizedEditor.clipRegions.map((region: ClipRegion) => region.id),);- nextSpeedIdRef.current = deriveNextId(- "speed",- normalizedEditor.speedRegions.map((region) => region.id),- );nextAudioIdRef.current = deriveNextId("audio",normalizedEditor.audioRegions.map((region) => region.id),@@ -2796,6 +2771,11 @@ export default function VideoEditor() {const id = `clip-${nextClipIdRef.current++}`;autoFullTrackClipIdRef.current = id;autoFullTrackClipEndMsRef.current = totalMs;+ if (trimRegions.length > 0) {+ setClipRegions(trimsToClips(trimRegions, totalMs));+ clipInitializedRef.current = true;+ return;+ }setClipRegions([{ id, startMs: 0, endMs: totalMs, speed: 1 }]);}clipInitializedRef.current = true;@@ -2812,7 +2792,7 @@ export default function VideoEditor() {autoFullTrackClipEndMsRef.current = totalMs;setClipRegions(extendedClipRegions);- }, [duration, clipRegions]);+ }, [duration, clipRegions, trimRegions]);// Derive trimRegions from clipRegions so export/playback pipelines stay unchangeduseEffect(() => {@@ -2822,27 +2802,12 @@ export default function VideoEditor() {}, [clipRegions, duration]);const mapTimelineTimeToSourceTime = useCallback(- (timeMs: number) => {- for (const clip of clipRegions) {- if (timeMs < clip.startMs || timeMs > clip.endMs) continue;- const speed = Number.isFinite(clip.speed) && clip.speed > 0 ? clip.speed : 1;- return Math.round(clip.startMs + (timeMs - clip.startMs) * speed);- }- return Math.round(timeMs);- },+ (timeMs: number) => resolveTimelineTimeToSourceTime(timeMs, clipRegions),[clipRegions],);const mapSourceTimeToTimelineTime = useCallback(- (timeMs: number) => {- for (const clip of clipRegions) {- const sourceEndMs = getClipSourceEndMs(clip);- if (timeMs < clip.startMs || timeMs > sourceEndMs) continue;- const speed = Number.isFinite(clip.speed) && clip.speed > 0 ? clip.speed : 1;- return Math.round(clip.startMs + (timeMs - clip.startMs) / speed);- }- return Math.round(timeMs);- },+ (timeMs: number) => resolveSourceTimeToTimelineTime(timeMs, clipRegions),[clipRegions],);@@ -2910,7 +2875,6 @@ export default function VideoEditor() {setSelectedZoomId(id);if (id) {setActiveEffectSection("zoom");- setSelectedTrimId(null);setSelectedAnnotationId(null);setSelectedAudioId(null);} else {@@ -2918,20 +2882,10 @@ export default function VideoEditor() {}}, []);- const handleSelectTrim = useCallback((id: string | null) => {- setSelectedTrimId(id);- if (id) {- setSelectedZoomId(null);- setSelectedAnnotationId(null);- setSelectedAudioId(null);- }- }, []);-const handleSelectAnnotation = useCallback((id: string | null) => {setSelectedAnnotationId(id);if (id) {setSelectedZoomId(null);- setSelectedTrimId(null);setSelectedAudioId(null);}}, []);@@ -2954,7 +2908,6 @@ export default function VideoEditor() {}setZoomRegions((prev) => [...prev, newRegion]);setSelectedZoomId(id);- setSelectedTrimId(null);setSelectedAnnotationId(null);extensionHost.emitEvent({type: "timeline:region-added",@@ -3048,19 +3001,6 @@ export default function VideoEditor() {zoomRegions,]);- const handleTrimAdded = useCallback((span: Span) => {- const id = `trim-${nextTrimIdRef.current++}`;- const newRegion: TrimRegion = {- id,- startMs: Math.round(span.start),- endMs: Math.round(span.end),- };- setTrimRegions((prev) => [...prev, newRegion]);- setSelectedTrimId(id);- setSelectedZoomId(null);- setSelectedAnnotationId(null);- }, []);-const handleZoomSpanChange = useCallback((id: string, span: Span) => {setZoomRegions((prev) =>prev.map((region) =>@@ -3071,21 +3011,7 @@ export default function VideoEditor() {endMs: Math.round(span.end),}: region,- ),- );- }, []);-- const handleTrimSpanChange = useCallback((id: string, span: Span) => {- setTrimRegions((prev) =>- prev.map((region) =>- region.id === id- ? {- ...region,- startMs: Math.round(span.start),- endMs: Math.round(span.end),- }- : region,- ),+ ),);}, []);@@ -3141,16 +3067,6 @@ export default function VideoEditor() {[selectedZoomId],);- const handleTrimDelete = useCallback(- (id: string) => {- setTrimRegions((prev) => prev.filter((region) => region.id !== id));- if (selectedTrimId === id) {- setSelectedTrimId(null);- }- },- [selectedTrimId],- );-const handleSelectClip = useCallback((id: string | null) => {setSelectedClipId(id);if (id) {@@ -3329,62 +3245,11 @@ export default function VideoEditor() {[clipRegions, selectedClipId],);- const handleSelectSpeed = useCallback((id: string | null) => {- setSelectedSpeedId(id);- if (id) {- setSelectedZoomId(null);- setSelectedTrimId(null);- setSelectedAnnotationId(null);- setSelectedAudioId(null);- }- }, []);-- const handleSpeedAdded = useCallback((span: Span) => {- const id = `speed-${nextSpeedIdRef.current++}`;- const newRegion: SpeedRegion = {- id,- startMs: Math.round(span.start),- endMs: Math.round(span.end),- speed: DEFAULT_PLAYBACK_SPEED,- };- setSpeedRegions((prev) => [...prev, newRegion]);- setSelectedSpeedId(id);- setSelectedZoomId(null);- setSelectedTrimId(null);- setSelectedAnnotationId(null);- }, []);-- const handleSpeedSpanChange = useCallback((id: string, span: Span) => {- setSpeedRegions((prev) =>- prev.map((region) =>- region.id === id- ? {- ...region,- startMs: Math.round(span.start),- endMs: Math.round(span.end),- }- : region,- ),- );- }, []);-- const handleSpeedDelete = useCallback(- (id: string) => {- setSpeedRegions((prev) => prev.filter((region) => region.id !== id));- if (selectedSpeedId === id) {- setSelectedSpeedId(null);- }- },- [selectedSpeedId],- );-const handleSelectAudio = useCallback((id: string | null) => {setSelectedAudioId(id);if (id) {setSelectedZoomId(null);- setSelectedTrimId(null);setSelectedAnnotationId(null);- setSelectedSpeedId(null);}}, []);@@ -3401,9 +3266,7 @@ export default function VideoEditor() {setAudioRegions((prev) => [...prev, newRegion]);setSelectedAudioId(id);setSelectedZoomId(null);- setSelectedTrimId(null);setSelectedAnnotationId(null);- setSelectedSpeedId(null);}, []);const handleAudioSpanChange = useCallback((id: string, span: Span, trackIndex?: number) => {@@ -3455,18 +3318,6 @@ export default function VideoEditor() {[selectedAudioId],);- const handleSpeedChange = useCallback(- (speed: PlaybackSpeed) => {- if (!selectedSpeedId) return;- setSpeedRegions((prev) =>- prev.map((region) =>- region.id === selectedSpeedId ? { ...region, speed } : region,- ),- );- },- [selectedSpeedId],- );-const handleAnnotationAdded = useCallback((span: Span, trackIndex = 0) => {const id = `annotation-${nextAnnotationIdRef.current++}`;const zIndex = nextAnnotationZIndexRef.current++; // Assign z-index based on creation order@@ -3485,7 +3336,6 @@ export default function VideoEditor() {setAnnotationRegions((prev) => [...prev, newRegion]);setSelectedAnnotationId(id);setSelectedZoomId(null);- setSelectedTrimId(null);}, []);const handleAnnotationSpanChange = useCallback(@@ -3686,12 +3536,6 @@ export default function VideoEditor() {}}, [selectedZoomId, zoomRegions]);- useEffect(() => {- if (selectedTrimId && !trimRegions.some((region) => region.id === selectedTrimId)) {- setSelectedTrimId(null);- }- }, [selectedTrimId, trimRegions]);-useEffect(() => {if (selectedAnnotationId &&@@ -3701,12 +3545,6 @@ export default function VideoEditor() {}}, [selectedAnnotationId, annotationRegions]);- useEffect(() => {- if (selectedSpeedId && !speedRegions.some((region) => region.id === selectedSpeedId)) {- setSelectedSpeedId(null);- }- }, [selectedSpeedId, speedRegions]);-useEffect(() => {if (selectedAudioId && !audioRegions.some((region) => region.id === selectedAudioId)) {setSelectedAudioId(null);@@ -3891,7 +3729,7 @@ export default function VideoEditor() {// Sync audio playback with video currentTime and isPlaying stateuseEffect(() => {const currentTimeMs = currentTime * 1000;- const activeSpeedRegion = speedRegions.find(+ const activeSpeedRegion = effectiveSpeedRegions.find((region) => currentTimeMs >= region.startMs && currentTimeMs < region.endMs,);const targetPlaybackRate = activeSpeedRegion ? activeSpeedRegion.speed : 1;@@ -3925,7 +3763,7 @@ export default function VideoEditor() {}}}- }, [isPlaying, currentTime, audioRegions, speedRegions]);+ }, [isPlaying, currentTime, audioRegions, effectiveSpeedRegions]);useEffect(() => {if (previewSourceAudioFallbackPaths.length === 0) {@@ -3933,7 +3771,7 @@ export default function VideoEditor() {return;}- const activeSpeedRegion = speedRegions.find(+ const activeSpeedRegion = effectiveSpeedRegions.find((region) => currentTime * 1000 >= region.startMs && currentTime * 1000 < region.endMs,);const targetPlaybackRate = activeSpeedRegion ? activeSpeedRegion.speed : 1;@@ -3987,8 +3825,8 @@ export default function VideoEditor() {isPlaying,previewSourceAudioFallbackPaths,sourceAudioFallbackStartDelayMsByPath,- speedRegions,- ]);+ effectiveSpeedRegions,+ ]);const showExportSuccessToast = useCallback((filePath: string) => {toast.success(`Exported successfully to ${filePath}`, {@@ -5349,8 +5187,6 @@ export default function VideoEditor() {selectedZoomId && handleZoomModeChange(mode)}onZoomDelete={handleZoomDelete}- selectedTrimId={selectedTrimId}- onTrimDelete={handleTrimDelete}selectedClipId={selectedClipId}selectedClipSpeed={selectedClipId@@ -5469,15 +5305,6 @@ export default function VideoEditor() {}onAnnotationBlurColorChange={handleAnnotationBlurColorChange}onAnnotationDelete={handleAnnotationDelete}- selectedSpeedId={selectedSpeedId}- selectedSpeedValue={- selectedSpeedId- ? (speedRegions.find((r) => r.id === selectedSpeedId)- ?.speed ?? null)- : null- }- onSpeedChange={handleSpeedChange}- onSpeedDelete={handleSpeedDelete}/>)}</div>@@ -5885,22 +5712,11 @@ export default function VideoEditor() {selectedZoomId={selectedZoomId}onSelectZoom={handleSelectZoom}trimRegions={trimRegions}- onTrimAdded={handleTrimAdded}- onTrimSpanChange={handleTrimSpanChange}- onTrimDelete={handleTrimDelete}- selectedTrimId={selectedTrimId}- onSelectTrim={handleSelectTrim}clipRegions={clipRegions}onClipSplit={handleClipSplit}onClipSpanChange={handleClipSpanChange}selectedClipId={selectedClipId}onSelectClip={handleSelectClip}- speedRegions={speedRegions}- onSpeedAdded={handleSpeedAdded}- onSpeedSpanChange={handleSpeedSpanChange}- onSpeedDelete={handleSpeedDelete}- selectedSpeedId={selectedSpeedId}- onSelectSpeed={handleSelectSpeed}audioRegions={audioRegions}onAudioAdded={handleAudioAdded}onAudioSpanChange={handleAudioSpanChange}diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsxindex 32643bec..6528c13b 100644--- a/src/components/video-editor/timeline/TimelineEditor.tsx+++ b/src/components/video-editor/timeline/TimelineEditor.tsx@@ -1048,11 +1048,11 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(selectedZoomId,onSelectZoom,trimRegions = [],- onTrimAdded,+ onTrimAdded: _onTrimAdded,onTrimSpanChange,- onTrimDelete,- selectedTrimId,- onSelectTrim,+ onTrimDelete: _onTrimDelete,+ selectedTrimId: _selectedTrimId,+ onSelectTrim: _onSelectTrim,clipRegions = [],onClipSplit,onClipSpanChange,@@ -1066,11 +1066,11 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(selectedAnnotationId,onSelectAnnotation,speedRegions = [],- onSpeedAdded,+ onSpeedAdded: _onSpeedAdded,onSpeedSpanChange,- onSpeedDelete,- selectedSpeedId,- onSelectSpeed,+ onSpeedDelete: _onSpeedDelete,+ selectedSpeedId: _selectedSpeedId,+ onSelectSpeed: _onSelectSpeed,audioRegions = [],onAudioAdded,onAudioSpanChange,@@ -1212,13 +1212,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(onSelectZoom(null);}, [selectedZoomId, onZoomDelete, onSelectZoom]);- // Delete selected trim item- const deleteSelectedTrim = useCallback(() => {- if (!selectedTrimId || !onTrimDelete || !onSelectTrim) return;- onTrimDelete(selectedTrimId);- onSelectTrim(null);- }, [selectedTrimId, onTrimDelete, onSelectTrim]);-const deleteSelectedClip = useCallback(() => {if (!selectedClipId || !onClipDelete || !onSelectClip) return;onClipDelete(selectedClipId);@@ -1231,12 +1224,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(onSelectAnnotation(null);}, [selectedAnnotationId, onAnnotationDelete, onSelectAnnotation]);- const deleteSelectedSpeed = useCallback(() => {- if (!selectedSpeedId || !onSpeedDelete || !onSelectSpeed) return;- onSpeedDelete(selectedSpeedId);- onSelectSpeed(null);- }, [selectedSpeedId, onSpeedDelete, onSelectSpeed]);-const deleteSelectedAudio = useCallback(() => {if (!selectedAudioId || !onAudioDelete || !onSelectAudio) return;onAudioDelete(selectedAudioId);@@ -1245,42 +1232,32 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(const clearSelectedBlocks = useCallback(() => {onSelectZoom(null);- onSelectTrim?.(null);onSelectClip?.(null);onSelectAnnotation?.(null);- onSelectSpeed?.(null);onSelectAudio?.(null);setSelectAllBlocksActive(false);}, [onSelectAnnotation,onSelectAudio,onSelectClip,- onSelectSpeed,- onSelectTrim,onSelectZoom,]);const hasAnyTimelineBlocks =zoomRegions.length > 0 ||- trimRegions.length > 0 ||clipRegions.length > 0 ||annotationRegions.length > 0 ||- speedRegions.length > 0 ||audioRegions.length > 0;const deleteAllBlocks = useCallback(() => {const zoomIds = zoomRegions.map((region) => region.id);- const trimIds = trimRegions.map((region) => region.id);const clipIds = clipRegions.map((region) => region.id);const annotationIds = annotationRegions.map((region) => region.id);- const speedIds = speedRegions.map((region) => region.id);const audioIds = audioRegions.map((region) => region.id);zoomIds.forEach((id) => onZoomDelete(id));- trimIds.forEach((id) => onTrimDelete?.(id));clipIds.forEach((id) => onClipDelete?.(id));annotationIds.forEach((id) => onAnnotationDelete?.(id));- speedIds.forEach((id) => onSpeedDelete?.(id));audioIds.forEach((id) => onAudioDelete?.(id));clearSelectedBlocks();@@ -1293,11 +1270,7 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(onAnnotationDelete,onAudioDelete,onClipDelete,- onSpeedDelete,- onTrimDelete,onZoomDelete,- speedRegions,- trimRegions,zoomRegions,]);@@ -1309,14 +1282,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>([onSelectZoom],);- const handleSelectTrim = useCallback(- (id: string | null) => {- setSelectAllBlocksActive(false);- onSelectTrim?.(id);- },- [onSelectTrim],- );-const handleSelectClip = useCallback((id: string | null) => {setSelectAllBlocksActive(false);@@ -1333,14 +1298,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>([onSelectAnnotation],);- const handleSelectSpeed = useCallback(- (id: string | null) => {- setSelectAllBlocksActive(false);- onSelectSpeed?.(id);- },- [onSelectSpeed],- );-const handleSelectAudio = useCallback((id: string | null) => {setSelectAllBlocksActive(false);@@ -1519,17 +1476,26 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(}const startPos = Math.max(0, Math.min(startMs, totalMs));+ const activeClip = clipRegions.find(+ (clip) => startPos >= clip.startMs && startPos < clip.endMs,+ );+ if (!activeClip) {+ return false;+ }+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;+ const gapToNextClipEdge = activeClip.endMs - startPos;+ const gapToNextRegion = nextRegion ? nextRegion.startMs - startPos : gapToNextClipEdge;+ const availableDuration = Math.min(gapToNextClipEdge, gapToNextRegion);const isOverlapping = sorted.some((region) => startPos >= region.startMs && startPos < region.endMs,);- return !isOverlapping && gapToNext >= defaultDuration;+ return !isOverlapping && availableDuration >= defaultDuration;},- [videoDuration, totalMs, zoomRegions, defaultRegionDurationMs],+ [videoDuration, totalMs, zoomRegions, defaultRegionDurationMs, clipRegions],);const addZoomAtMs = useCallback(@@ -1547,7 +1513,7 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(if (!canPlaceZoomAtMs(startPos)) {toast.error("Cannot place zoom here", {description:- "Zoom already exists at this location or not enough space available.",+ "Place zooms inside a kept clip and leave enough room before the clip ends.",});return;}@@ -1649,46 +1615,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(handleSuggestZooms();}, [autoSuggestZoomsTrigger, handleSuggestZooms, onAutoSuggestZoomsConsumed]);- const handleAddTrim = useCallback(() => {- if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onTrimAdded) {- return;- }-- const defaultDuration = Math.min(defaultRegionDurationMs, totalMs);- if (defaultDuration <= 0) {- return;- }-- // Always place trim at playhead- const startPos = Math.max(0, Math.min(currentTimeMs, totalMs));- // Find the next trim region after the playhead- const sorted = [...trimRegions].sort((a, b) => a.startMs - b.startMs);- const nextRegion = sorted.find((region) => region.startMs > startPos);- const gapToNext = nextRegion ? nextRegion.startMs - startPos : totalMs - startPos;-- // Check if playhead is inside any trim region- const isOverlapping = sorted.some(- (region) => startPos >= region.startMs && startPos < region.endMs,- );- if (isOverlapping || gapToNext <= 0) {- toast.error("Cannot place trim here", {- description:- "Trim already exists at this location or not enough space available.",- });- return;- }-- const actualDuration = Math.min(defaultRegionDurationMs, gapToNext);- onTrimAdded({ start: startPos, end: startPos + actualDuration });- }, [- videoDuration,- totalMs,- currentTimeMs,- trimRegions,- onTrimAdded,- defaultRegionDurationMs,- ]);-const handleSplitClip = useCallback(() => {if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onClipSplit) {return;@@ -1696,46 +1622,6 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(onClipSplit(currentTimeMs);}, [videoDuration, totalMs, currentTimeMs, onClipSplit]);- const handleAddSpeed = useCallback(() => {- if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onSpeedAdded) {- return;- }-- const defaultDuration = Math.min(defaultRegionDurationMs, totalMs);- if (defaultDuration <= 0) {- return;- }-- // Always place speed region at playhead- const startPos = Math.max(0, Math.min(currentTimeMs, totalMs));- // Find the next speed region after the playhead- const sorted = [...speedRegions].sort((a, b) => a.startMs - b.startMs);- const nextRegion = sorted.find((region) => region.startMs > startPos);- const gapToNext = nextRegion ? nextRegion.startMs - startPos : totalMs - startPos;-- // Check if playhead is inside any speed region- const isOverlapping = sorted.some(- (region) => startPos >= region.startMs && startPos < region.endMs,- );- if (isOverlapping || gapToNext <= 0) {- toast.error("Cannot place speed here", {- description:- "Speed region already exists at this location or not enough space available.",- });- return;- }-- const actualDuration = Math.min(defaultRegionDurationMs, gapToNext);- onSpeedAdded({ start: startPos, end: startPos + actualDuration });- }, [- videoDuration,- totalMs,- currentTimeMs,- speedRegions,- onSpeedAdded,- defaultRegionDurationMs,- ]);-const handleAddAudio = useCallback(async (preferredTrackIndex?: number) => {if (!videoDuration || videoDuration === 0 || totalMs === 0 || !onAudioAdded) {@@ -1918,18 +1804,12 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(if (matchesShortcut(e, keyShortcuts.addZoom, isMac)) {handleAddZoom();}- if (matchesShortcut(e, keyShortcuts.addTrim, isMac)) {- handleAddTrim();- }if (matchesShortcut(e, keyShortcuts.splitClip, isMac)) {handleSplitClip();}if (matchesShortcut(e, keyShortcuts.addAnnotation, isMac)) {handleAddAnnotation();}- if (matchesShortcut(e, keyShortcuts.addSpeed, isMac)) {- handleAddSpeed();- }// Tab: Cycle through overlapping annotations at current timeif (e.key === "Tab" && annotationRegions.length > 0) {@@ -1970,14 +1850,10 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(deleteSelectedKeyframe();} else if (selectedZoomId) {deleteSelectedZoom();- } else if (selectedTrimId) {- deleteSelectedTrim();} else if (selectedClipId) {deleteSelectedClip();} else if (selectedAnnotationId) {deleteSelectedAnnotation();- } else if (selectedSpeedId) {- deleteSelectedSpeed();} else if (selectedAudioId) {deleteSelectedAudio();}@@ -1988,24 +1864,18 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(}, [addKeyframe,handleAddZoom,- handleAddTrim,handleSplitClip,handleAddAnnotation,- handleAddSpeed,deleteAllBlocks,deleteSelectedKeyframe,deleteSelectedZoom,- deleteSelectedTrim,deleteSelectedClip,deleteSelectedAnnotation,- deleteSelectedSpeed,deleteSelectedAudio,selectedKeyframeId,selectedZoomId,- selectedTrimId,selectedClipId,selectedAnnotationId,- selectedSpeedId,selectedAudioId,annotationRegions,currentTimeMs,@@ -2479,16 +2349,12 @@ const TimelineEditor = forwardRef<TimelineEditorHandle, TimelineEditorProps>(onAddZoomAtMs={addZoomAtMs}canPlaceZoomAtMs={canPlaceZoomAtMs}onSelectZoom={handleSelectZoom}- onSelectTrim={handleSelectTrim}onSelectClip={handleSelectClip}onSelectAnnotation={handleSelectAnnotation}- onSelectSpeed={handleSelectSpeed}onSelectAudio={handleSelectAudio}selectedZoomId={selectedZoomId}- selectedTrimId={selectedTrimId}selectedClipId={selectedClipId}selectedAnnotationId={selectedAnnotationId}- selectedSpeedId={selectedSpeedId}selectedAudioId={selectedAudioId}selectAllBlocksActive={selectAllBlocksActive}onClearBlockSelection={clearSelectedBlocks}diff --git a/src/components/video-editor/types.test.ts b/src/components/video-editor/types.test.tsindex 1d4412f1..12a63cb3 100644--- a/src/components/video-editor/types.test.ts+++ b/src/components/video-editor/types.test.ts@@ -1,6 +1,11 @@import { describe, expect, it } from "vitest";-import { extendAutoFullTrackClip } from "./types";+import {+ extendAutoFullTrackClip,+ findClipAtTimelineTime,+ mapSourceTimeToTimelineTime,+ mapTimelineTimeToSourceTime,+} from "./types";describe("extendAutoFullTrackClip", () => {it("extends the default full-track clip when metadata duration grows", () => {@@ -105,3 +110,35 @@ describe("extendAutoFullTrackClip", () => {).toBeNull();});});++describe("clip timeline mapping", () => {+ const clips = [+ { id: "clip-1", startMs: 0, endMs: 4_000, speed: 1 },+ { id: "clip-2", startMs: 6_000, endMs: 8_000, speed: 2 },+ ];++ it("maps kept timeline time into source time", () => {+ expect(mapTimelineTimeToSourceTime(1_500, clips)).toBe(1_500);+ expect(mapTimelineTimeToSourceTime(7_000, clips)).toBe(8_000);+ });++ it("snaps timeline gaps to the nearest clip edge", () => {+ expect(mapTimelineTimeToSourceTime(4_300, clips)).toBe(4_000);+ expect(mapTimelineTimeToSourceTime(5_700, clips)).toBe(6_000);+ });++ it("maps kept source time back into timeline time", () => {+ expect(mapSourceTimeToTimelineTime(1_500, clips)).toBe(1_500);+ expect(mapSourceTimeToTimelineTime(8_000, clips)).toBe(7_000);+ });++ it("snaps removed source gaps to the nearest kept boundary", () => {+ expect(mapSourceTimeToTimelineTime(4_200, clips)).toBe(4_000);+ expect(mapSourceTimeToTimelineTime(5_900, clips)).toBe(6_000);+ });++ it("finds clips only inside visible kept spans", () => {+ expect(findClipAtTimelineTime(500, clips)?.id).toBe("clip-1");+ expect(findClipAtTimelineTime(5_000, clips)).toBeNull();+ });+});diff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.tsindex ec29d812..088a0f7d 100644--- a/src/components/video-editor/types.ts+++ b/src/components/video-editor/types.ts@@ -155,6 +155,92 @@ export function getClipSourceEndMs(clip: ClipRegion): number {return Math.round(clip.startMs + displayDurationMs * speed);}+export function sortClipRegions(clips: ClipRegion[]): ClipRegion[] {+ return [...clips].sort((left, right) => left.startMs - right.startMs);+}++function getSafeClipSpeed(clip: ClipRegion) {+ return Number.isFinite(clip.speed) && clip.speed > 0 ? clip.speed : 1;+}++function clampToNearestClipBoundary(+ timeMs: number,+ clips: ClipRegion[],+ kind: "timeline" | "source",+) {+ let nearestTimeMs = Math.round(timeMs);+ let nearestDistance = Number.POSITIVE_INFINITY;++ for (const clip of clips) {+ const boundaries =+ kind === "timeline"+ ? [clip.startMs, clip.endMs]+ : [clip.startMs, getClipSourceEndMs(clip)];++ for (const boundary of boundaries) {+ const distance = Math.abs(timeMs - boundary);+ if (distance < nearestDistance) {+ nearestDistance = distance;+ nearestTimeMs = Math.round(boundary);+ }+ }+ }++ return nearestTimeMs;+}++export function mapTimelineTimeToSourceTime(timeMs: number, clips: ClipRegion[]): number {+ const roundedTimeMs = Math.round(timeMs);+ const sortedClips = sortClipRegions(clips);++ for (const clip of sortedClips) {+ if (roundedTimeMs < clip.startMs || roundedTimeMs > clip.endMs) {+ continue;+ }++ return Math.round(+ clip.startMs + (roundedTimeMs - clip.startMs) * getSafeClipSpeed(clip),+ );+ }++ if (sortedClips.length === 0) {+ return roundedTimeMs;+ }++ return clampToNearestClipBoundary(roundedTimeMs, sortedClips, "timeline");+}++export function mapSourceTimeToTimelineTime(timeMs: number, clips: ClipRegion[]): number {+ const roundedTimeMs = Math.round(timeMs);+ const sortedClips = sortClipRegions(clips);++ for (const clip of sortedClips) {+ const sourceEndMs = getClipSourceEndMs(clip);+ if (roundedTimeMs < clip.startMs || roundedTimeMs > sourceEndMs) {+ continue;+ }++ return Math.round(+ clip.startMs + (roundedTimeMs - clip.startMs) / getSafeClipSpeed(clip),+ );+ }++ if (sortedClips.length === 0) {+ return roundedTimeMs;+ }++ return clampToNearestClipBoundary(roundedTimeMs, sortedClips, "source");+}++export function findClipAtTimelineTime(timeMs: number, clips: ClipRegion[]): ClipRegion | null {+ const roundedTimeMs = Math.round(timeMs);+ return (+ sortClipRegions(clips).find(+ (clip) => roundedTimeMs >= clip.startMs && roundedTimeMs < clip.endMs,+ ) ?? null+ );+}+export function extendAutoFullTrackClip(clips: ClipRegion[],autoClipId: string | null,diff --git a/src/components/video-editor/videoPlayback/videoEventHandlers.test.ts b/src/components/video-editor/videoPlayback/videoEventHandlers.test.tsindex aca357f9..44414c53 100644--- a/src/components/video-editor/videoPlayback/videoEventHandlers.test.ts+++ b/src/components/video-editor/videoPlayback/videoEventHandlers.test.ts@@ -151,4 +151,29 @@ describe("createVideoEventHandlers", () => {handlers.dispose();expect(cancelVideoFrameCallback).toHaveBeenCalledWith(23);});++ it("skips removed footage after a paused seek", () => {+ const video = createMockVideo({+ currentTime: 1.25,+ paused: true,+ });+ const onTimeUpdate = vi.fn();+ const handlers = createVideoEventHandlers({+ video,+ isSeekingRef: createMutableRef(true),+ isPlayingRef: createMutableRef(false),+ allowPlaybackRef: createMutableRef(true),+ currentTimeRef: createMutableRef(0),+ timeUpdateAnimationRef: createMutableRef<number | null>(null),+ onPlayStateChange: vi.fn(),+ onTimeUpdate,+ trimRegionsRef: createMutableRef([{ id: "trim-1", startMs: 1000, endMs: 2000 }]),+ speedRegionsRef: createMutableRef([]),+ });++ handlers.handleSeeked();++ expect(video.currentTime).toBe(2);+ expect(onTimeUpdate).toHaveBeenLastCalledWith(2);+ });});diff --git a/src/components/video-editor/videoPlayback/videoEventHandlers.ts b/src/components/video-editor/videoPlayback/videoEventHandlers.tsindex fd544654..113d420b 100644--- a/src/components/video-editor/videoPlayback/videoEventHandlers.ts+++ b/src/components/video-editor/videoPlayback/videoEventHandlers.ts@@ -167,8 +167,8 @@ export function createVideoEventHandlers(params: VideoEventHandlersParams) {const currentTimeMs = video.currentTime * 1000;const activeTrimRegion = findActiveTrimRegion(currentTimeMs);- // If we seeked into a trim region while playing, skip to the end- if (activeTrimRegion && isPlayingRef.current && !video.paused) {+ // Never leave the preview parked on removed footage after a seek.+ if (activeTrimRegion) {skipPastTrimRegion(activeTrimRegion);} else {emitTime(video.currentTime);diff --git a/src/lib/shortcuts.ts b/src/lib/shortcuts.tsindex f1bc84b4..d2d9828c 100644--- a/src/lib/shortcuts.ts+++ b/src/lib/shortcuts.ts@@ -1,8 +1,6 @@export const SHORTCUT_ACTIONS = ["addZoom",- "addTrim","splitClip",- "addSpeed","addAnnotation","addKeyframe","deleteSelected",@@ -76,9 +74,7 @@ export function findConflict(export const DEFAULT_SHORTCUTS: ShortcutsConfig = {addZoom: { key: "z" },- addTrim: { key: "t" },splitClip: { key: "c" },- addSpeed: { key: "s" },addAnnotation: { key: "a" },addKeyframe: { key: "f" },deleteSelected: { key: "d", ctrl: true },@@ -87,9 +83,7 @@ export const DEFAULT_SHORTCUTS: ShortcutsConfig = {export const SHORTCUT_LABELS: Record<ShortcutAction, string> = {addZoom: "Add Zoom",- addTrim: "Add Trim",splitClip: "Split Clip",- addSpeed: "Add Speed",addAnnotation: "Add Annotation",addKeyframe: "Add Keyframe",deleteSelected: "Delete Selected",