fix(studio): keep layer selection seek within clip range

This commit is contained in:
func25
2026-05-13 15:58:49 +07:00
parent 9fe356be14
commit 039c2b4402
3 changed files with 49 additions and 5 deletions
@@ -158,6 +158,20 @@ export function findMatchingTimelineElementId(
return null;
}
export function resolveTimelineSelectionSeekTime(
currentTime: number,
element: Pick<TimelineElement, "start" | "duration"> | null | undefined,
): number | null {
if (!element) return null;
if (!Number.isFinite(element.start) || !Number.isFinite(element.duration)) return null;
const start = Math.max(0, element.start);
const end = Math.max(start, start + Math.max(0, element.duration));
const time = Number.isFinite(currentTime) ? currentTime : start;
return clampNumber(time, start, end);
}
export function clampNumber(value: number, min: number, max: number): number {
if (max < min) return min;
return Math.min(Math.max(value, min), max);