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(); + }); });