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 {
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 };
}

View File

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