Skip to content

Commit 3e342cf

Browse files
committed
fix(studio): keep sub-compositions expanded at the end of the timeline
Auto-expansion picks the composition whose clip window contains the playhead, and those windows are half-open. With the playhead parked on the last clip's end - where playback stops - it sat inside nothing, so every expanded sub-composition row and its keyframe lanes collapsed to a single host row. Accept the closing boundary, but only when the strict pass matched nothing, so a playhead on the seam between two adjacent clips still expands the one that is starting.
1 parent 099d891 commit 3e342cf

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

‎packages/studio/src/player/hooks/useExpandedTimelineElements.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,49 @@ describe("resolveTimelineExpansionRawId", () => {
278278
).toBe("scene");
279279
});
280280

281+
it("THE BUG: keeps a composition expanded with the playhead parked on its end", () => {
282+
// Clip windows are half-open, so at the very end of the timeline the
283+
// playhead was inside nothing and every expanded row collapsed.
284+
const manifest = [
285+
clip({ id: "scene", start: 0, duration: 12 }),
286+
clip({ id: "headline", start: 0, duration: 12 }),
287+
];
288+
const parentMap = new Map([["headline", "scene"]]);
289+
290+
expect(
291+
resolveTimelineExpansionRawId({
292+
selectedElementId: null,
293+
isPlaying: false,
294+
currentTime: 12,
295+
manifest,
296+
parentMap,
297+
}),
298+
).toBe("scene");
299+
});
300+
301+
it("prefers the starting clip over the ending one on a shared seam", () => {
302+
const manifest = [
303+
clip({ id: "first", start: 0, duration: 5 }),
304+
clip({ id: "first-child", start: 0, duration: 5 }),
305+
clip({ id: "second", start: 5, duration: 5 }),
306+
clip({ id: "second-child", start: 5, duration: 5 }),
307+
];
308+
const parentMap = new Map([
309+
["first-child", "first"],
310+
["second-child", "second"],
311+
]);
312+
313+
expect(
314+
resolveTimelineExpansionRawId({
315+
selectedElementId: null,
316+
isPlaying: false,
317+
currentTime: 5,
318+
manifest,
319+
parentMap,
320+
}),
321+
).toBe("second");
322+
});
323+
281324
it("auto-expands the innermost active nested composition when paused", () => {
282325
const manifest = [
283326
clip({ id: "outer", start: 0, duration: 10 }),

‎packages/studio/src/player/hooks/useExpandedTimelineElements.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ function clipContainsTime(clip: ClipManifestClip, time: number): boolean {
4545
return Number.isFinite(time) && time >= clip.start && time < clip.start + clip.duration;
4646
}
4747

48+
/** Half-open containment plus the closing boundary — see the fallback below. */
49+
function clipTouchesTime(clip: ClipManifestClip, time: number): boolean {
50+
return Number.isFinite(time) && time >= clip.start && time <= clip.start + clip.duration;
51+
}
52+
4853
function getActiveParentDepth(id: string, parentMap: Map<string, string>, activeIds: Set<string>) {
4954
let depth = 0;
5055
let parent = parentMap.get(id);
@@ -65,11 +70,20 @@ function findActiveExpandableCompositionId(
6570
parentMap: Map<string, string>,
6671
): string | null {
6772
const parentIds = new Set(parentMap.values());
68-
const activeIds = new Set<string>();
69-
for (const clip of manifest) {
70-
if (!clip.id || !parentIds.has(clip.id) || !clipContainsTime(clip, currentTime)) continue;
71-
activeIds.add(clip.id);
72-
}
73+
const collect = (matches: (clip: ClipManifestClip, time: number) => boolean) => {
74+
const ids = new Set<string>();
75+
for (const clip of manifest) {
76+
if (clip.id && parentIds.has(clip.id) && matches(clip, currentTime)) ids.add(clip.id);
77+
}
78+
return ids;
79+
};
80+
// Clip windows are half-open, so a playhead parked exactly on a clip's end is
81+
// inside nothing — at the end of the timeline that collapsed every expanded
82+
// sub-composition row and its keyframe lanes. Only when the strict pass finds
83+
// nothing do we accept the closing boundary, so a playhead landing on the seam
84+
// between two adjacent clips still expands the one that is starting.
85+
const strict = collect(clipContainsTime);
86+
const activeIds = strict.size > 0 ? strict : collect(clipTouchesTime);
7387
let bestId: string | null = null;
7488
let bestDepth = -1;
7589
for (const id of activeIds) {

0 commit comments

Comments
 (0)