From c01981fd5e20a49a27ab3e62db9333d52b9169d9 Mon Sep 17 00:00:00 2001 From: webadderall <131426131+webadderall@users.noreply.github.com> Date: Tue, 5 May 2026 11:43:04 +1000 Subject: [PATCH] fix: address PR review regressions --- electron/electron-env.d.ts | 4 ++-- electron/preload.ts | 8 ++++---- src/components/video-editor/VideoEditor.tsx | 7 ++++++- .../video-editor/timeline/TimelineEditor.tsx | 9 +++++++-- src/components/video-editor/types.test.ts | 15 +++++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts index d7ba1fe9..d46b4770 100644 --- a/electron/electron-env.d.ts +++ b/electron/electron-env.d.ts @@ -151,12 +151,12 @@ interface Window { message?: string; error?: string; }>; - pauseCursorCapture: () => Promise<{ + pauseCursorCapture: (boundaryMs?: number) => Promise<{ success: boolean; message?: string; error?: string; }>; - resumeCursorCapture: () => Promise<{ + resumeCursorCapture: (boundaryMs?: number) => Promise<{ success: boolean; message?: string; error?: string; diff --git a/electron/preload.ts b/electron/preload.ts index acc756e8..fb1f9f5e 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -293,11 +293,11 @@ contextBridge.exposeInMainWorld("electronAPI", { resumeNativeScreenRecording: () => { return ipcRenderer.invoke("resume-native-screen-recording"); }, - pauseCursorCapture: () => { - return ipcRenderer.invoke("pause-cursor-capture"); + pauseCursorCapture: (boundaryMs?: number) => { + return ipcRenderer.invoke("pause-cursor-capture", boundaryMs); }, - resumeCursorCapture: () => { - return ipcRenderer.invoke("resume-cursor-capture"); + resumeCursorCapture: (boundaryMs?: number) => { + return ipcRenderer.invoke("resume-cursor-capture", boundaryMs); }, startFfmpegRecording: (source: ProcessedDesktopSource) => { return ipcRenderer.invoke("start-ffmpeg-recording", source); diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx index cb184632..89911aa7 100644 --- a/src/components/video-editor/VideoEditor.tsx +++ b/src/components/video-editor/VideoEditor.tsx @@ -3076,7 +3076,12 @@ export default function VideoEditor() { autoFullTrackClipIdRef.current = id; autoFullTrackClipEndMsRef.current = totalMs; if (trimRegions.length > 0) { - setClipRegions(trimsToClips(trimRegions, totalMs)); + const derivedClipRegions = trimsToClips(trimRegions, totalMs); + nextClipIdRef.current = deriveNextId( + "clip", + derivedClipRegions.map((region) => region.id), + ); + setClipRegions(derivedClipRegions); clipInitializedRef.current = true; return; } diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx index 538337b9..bb591220 100644 --- a/src/components/video-editor/timeline/TimelineEditor.tsx +++ b/src/components/video-editor/timeline/TimelineEditor.tsx @@ -1479,10 +1479,15 @@ const TimelineEditor = forwardRef( const activeClip = clipRegions.find( (clip) => startPos >= clip.startMs && startPos < clip.endMs, ); + const nextClip = clipRegions.find((clip) => clip.startMs > startPos); const sorted = [...zoomRegions].sort((a, b) => a.startMs - b.startMs); const nextRegion = sorted.find((region) => region.startMs > startPos); - const gapToNextClipEdge = activeClip ? activeClip.endMs - startPos : totalMs - startPos; + const gapToNextClipEdge = activeClip + ? activeClip.endMs - startPos + : nextClip + ? nextClip.startMs - startPos + : 0; const gapToNextRegion = nextRegion ? nextRegion.startMs - startPos : totalMs - startPos; const availableDuration = Math.min(gapToNextClipEdge, gapToNextRegion); @@ -1490,7 +1495,7 @@ const TimelineEditor = forwardRef( (region) => startPos >= region.startMs && startPos < region.endMs, ); - return !isOverlapping && availableDuration >= defaultDuration; + return !isOverlapping && availableDuration >= defaultRegionDurationMs; }, [videoDuration, totalMs, zoomRegions, defaultRegionDurationMs, clipRegions], ); diff --git a/src/components/video-editor/types.test.ts b/src/components/video-editor/types.test.ts index 12a63cb3..4333ce5e 100644 --- a/src/components/video-editor/types.test.ts +++ b/src/components/video-editor/types.test.ts @@ -5,7 +5,9 @@ import { findClipAtTimelineTime, mapSourceTimeToTimelineTime, mapTimelineTimeToSourceTime, + trimsToClips, } from "./types"; +import { deriveNextId } from "./projectPersistence"; describe("extendAutoFullTrackClip", () => { it("extends the default full-track clip when metadata duration grows", () => { @@ -141,4 +143,17 @@ describe("clip timeline mapping", () => { expect(findClipAtTimelineTime(500, clips)?.id).toBe("clip-1"); expect(findClipAtTimelineTime(5_000, clips)).toBeNull(); }); + + it("derives the next clip id after converting trim gaps into clip ids", () => { + const clipsFromTrims = trimsToClips( + [ + { id: "trim-gap-1", startMs: 1_000, endMs: 2_000 }, + { id: "trim-gap-2", startMs: 4_000, endMs: 5_000 }, + ], + 6_000, + ); + + expect(clipsFromTrims.map((clip) => clip.id)).toEqual(["clip-1", "clip-2", "clip-3"]); + expect(deriveNextId("clip", clipsFromTrims.map((clip) => clip.id))).toBe(4); + }); });