fix: guard against zero-length clip at EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-23 02:32:46 -04:00
parent 507e3b79b7
commit d7a207154a
2 changed files with 16 additions and 8 deletions

View File

@@ -8,21 +8,25 @@ export function computeQuickClipRange(
): { start: number; end: number } | null { ): { start: number; end: number } | null {
if (duration === 0) return null; if (duration === 0) return null;
let start: number;
let end: number;
switch (position) { switch (position) {
case 'at': case 'at':
return { start = currentTime;
start: currentTime, end = Math.min(currentTime + clipDuration, duration);
end: Math.min(currentTime + clipDuration, duration), break;
};
case 'before': case 'before':
return { start = Math.max(currentTime - clipDuration, 0);
start: Math.max(currentTime - clipDuration, 0), end = currentTime;
end: currentTime, break;
};
default: { default: {
const _exhaustive: never = position; const _exhaustive: never = position;
void _exhaustive; void _exhaustive;
return null; return null;
} }
} }
if (start >= end) return null;
return { start, end };
} }

View File

@@ -40,4 +40,8 @@ describe('computeQuickClipRange', () => {
const result = computeQuickClipRange(120, 120, 'before'); const result = computeQuickClipRange(120, 120, 'before');
expect(result).toEqual({ start: 110, end: 120 }); expect(result).toEqual({ start: 110, end: 120 });
}); });
it('"at" returns null when currentTime equals duration', () => {
expect(computeQuickClipRange(120, 120, 'at')).toBeNull();
});
}); });