From d7a207154ac758746d2e614768a87db6dd2e44b2 Mon Sep 17 00:00:00 2001 From: cottongin Date: Wed, 23 Sep 2026 02:32:46 -0400 Subject: [PATCH] fix: guard against zero-length clip at EOF Co-authored-by: Cursor --- src/lib/utils/clipRange.ts | 20 ++++++++++++-------- tests/lib/utils/clipRange.test.ts | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lib/utils/clipRange.ts b/src/lib/utils/clipRange.ts index 86a75b1..3c74d43 100644 --- a/src/lib/utils/clipRange.ts +++ b/src/lib/utils/clipRange.ts @@ -8,21 +8,25 @@ export function computeQuickClipRange( ): { start: number; end: number } | null { if (duration === 0) return null; + let start: number; + let end: number; + switch (position) { case 'at': - return { - start: currentTime, - end: Math.min(currentTime + clipDuration, duration), - }; + start = currentTime; + end = Math.min(currentTime + clipDuration, duration); + break; case 'before': - return { - start: Math.max(currentTime - clipDuration, 0), - end: currentTime, - }; + start = Math.max(currentTime - clipDuration, 0); + end = currentTime; + break; default: { const _exhaustive: never = position; void _exhaustive; return null; } } + + if (start >= end) return null; + return { start, end }; } diff --git a/tests/lib/utils/clipRange.test.ts b/tests/lib/utils/clipRange.test.ts index d8e1fa6..ffefe2a 100644 --- a/tests/lib/utils/clipRange.test.ts +++ b/tests/lib/utils/clipRange.test.ts @@ -40,4 +40,8 @@ describe('computeQuickClipRange', () => { const result = computeQuickClipRange(120, 120, 'before'); expect(result).toEqual({ start: 110, end: 120 }); }); + + it('"at" returns null when currentTime equals duration', () => { + expect(computeQuickClipRange(120, 120, 'at')).toBeNull(); + }); });