fix: guard against zero-length clip at EOF
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user