Skip to content

Commit 7a3c7ad

Browse files
vanceingallsclaude
andcommitted
fix(studio): recompute keyframe currentPct from the corrected timing basis in the flat Layout group
Follow-up to 684ec4e: that fix corrected the seek target for Layout's keyframe gutter via deriveElementTiming, but currentPct — which drives KeyframeNavigation's diamond active/inactive state and prev/next arrow targeting — still used PropertyPanel's naive elStart=0/elDuration=1 basis. For an element with animations but no explicit data-duration, seeking to a keyframe's real absolute time no longer lit that keyframe's diamond as active, and the prev/next arrows targeted the wrong keyframes. Thread currentTime into PropertyPanelFlat (swapping the now-redundant currentPct prop 1-for-1, so PropertyPanel.tsx's line count is unchanged) and recompute currentPct there from the same deriveElementTiming basis already used for the seek fix. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent fae517d commit 7a3c7ad

3 files changed

Lines changed: 117 additions & 8 deletions

File tree

‎packages/studio/src/components/editor/PropertyPanel.test.tsx‎

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ async function renderPanel(
181181
flatEnabled: boolean,
182182
elementOverride: ReturnType<typeof baseElement> = baseElement(),
183183
propsOverride: Partial<PropertyPanelProps> = {},
184+
currentTime?: number,
184185
) {
185186
vi.resetModules();
186187
vi.doMock("./manualEditingAvailability", async () => {
@@ -189,6 +190,13 @@ async function renderPanel(
189190
);
190191
return { ...actual, STUDIO_FLAT_INSPECTOR_ENABLED: flatEnabled };
191192
});
193+
// Seed the playhead on the SAME store instance PropertyPanel.tsx will read via
194+
// usePlayerStore (module-fresh since the resetModules() above) — must happen
195+
// before PropertyPanel is imported/rendered so its initial render sees it.
196+
if (currentTime !== undefined) {
197+
const { usePlayerStore } = await import("../../player/store/playerStore");
198+
usePlayerStore.getState().setCurrentTime(currentTime);
199+
}
192200
const { PropertyPanel } = await import("./PropertyPanel");
193201
const host = document.createElement("div");
194202
document.body.append(host);
@@ -483,10 +491,20 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
483491
"Layout's X-row keyframe gutter seeks to the SAME absolute time Motion's Timing row shows as the midpoint (50% of an inferred 2s-5s range = 3.5s)",
484492
async () => {
485493
const onSeekToTime = vi.fn();
486-
const { host, root } = await renderPanel(true, inferredMotionElement(), {
487-
gsapAnimations: [INFERRED_TIMING_ANIMATION],
488-
onSeekToTime,
489-
});
494+
// Seed the playhead at the clip's real start (t=2, the 0% keyframe's
495+
// absolute time) — now that the follow-up fix also recomputes
496+
// `currentPct` from the corrected elStart/elDuration basis, "current
497+
// position is at the 0% keyframe" must be expressed as an actual t=2
498+
// seek rather than relying on the store's untouched t=0 default (which,
499+
// post-fix, resolves to a currentPct of -66.7% — well outside the 0%
500+
// keyframe's tolerance window, and no longer "the case the coherence
501+
// bug affected" that this test documents).
502+
const { host, root } = await renderPanel(
503+
true,
504+
inferredMotionElement(),
505+
{ gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },
506+
2,
507+
);
490508
openFlatGroup(host, "Layout");
491509
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
492510
if (!layoutGroup) throw new Error("expected the Layout group to be open");
@@ -498,7 +516,7 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
498516
const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');
499517
if (!gutter) throw new Error("expected a keyframe gutter on the X row");
500518
// The diamond button always carries a `title`; the two plain arrow
501-
// buttons don't. At currentPct=0 with keyframes at 0/50/100%, the prev
519+
// buttons don't. At currentPct=0 (playhead on the 0% keyframe), the prev
502520
// arrow is disabled (no earlier keyframe) and the next arrow seeks to
503521
// the 50% keyframe — exactly the case the coherence bug affected.
504522
const nextArrow = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button")).find(
@@ -514,3 +532,86 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe
514532
RENDER_TIMEOUT_MS,
515533
);
516534
});
535+
536+
// Follow-up fix (review of 684ec4e87): the seek-basis fix above corrected
537+
// WHERE a keyframe click seeks to, but `currentPct` — the value that drives
538+
// KeyframeNavigation's diamond active/inactive state and prev/next arrow
539+
// targeting — still used the OLD naive basis. For an inferred-duration
540+
// element, seeking to a keyframe's actual absolute time no longer lit that
541+
// keyframe's diamond as active. Prove the round-trip here: seek to the exact
542+
// absolute time of the 50% keyframe (2 + 0.5*3 = 3.5) and confirm its diamond
543+
// renders "active" (title="Remove x keyframe"), not "inactive"/"ghost".
544+
describe("PropertyPanel — flat Layout currentPct basis (currentPct follow-up fix)", () => {
545+
it(
546+
"lights the X-row keyframe diamond as active when the playhead is seeked to that keyframe's real absolute time (inferred 2s-5s range, 50% keyframe = 3.5s)",
547+
async () => {
548+
const { host, root } = await renderPanel(
549+
true,
550+
inferredMotionElement(),
551+
{ gsapAnimations: [INFERRED_TIMING_ANIMATION] },
552+
3.5,
553+
);
554+
openFlatGroup(host, "Layout");
555+
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
556+
if (!layoutGroup) throw new Error("expected the Layout group to be open");
557+
558+
const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(
559+
(el) => el.querySelector("span")?.textContent === "X",
560+
);
561+
if (!xRow) throw new Error("expected an X row");
562+
const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');
563+
if (!gutter) throw new Error("expected a keyframe gutter on the X row");
564+
const diamond = gutter.querySelector<HTMLButtonElement>("button[title]");
565+
if (!diamond) throw new Error("expected a keyframe diamond button");
566+
// KeyframeDiamond's title mapping: active -> "Remove ... keyframe",
567+
// inactive -> "Add ... keyframe", ghost -> "Convert ... to keyframes".
568+
// Before this fix, currentPct was computed against the naive
569+
// elStart=0/elDuration=1 basis, so t=3.5 produced currentPct=350% —
570+
// nowhere near the 50% keyframe within KeyframeNavigation's tolerance —
571+
// and the diamond stayed "inactive" even though the playhead was
572+
// exactly on that keyframe's real time.
573+
expect(diamond.title).toBe("Remove x keyframe");
574+
act(() => root.unmount());
575+
},
576+
RENDER_TIMEOUT_MS,
577+
);
578+
579+
it(
580+
"prev/next arrows re-center on the current keyframe once currentPct agrees with the corrected seek basis",
581+
async () => {
582+
const onSeekToTime = vi.fn();
583+
const { host, root } = await renderPanel(
584+
true,
585+
inferredMotionElement(),
586+
{ gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },
587+
3.5,
588+
);
589+
openFlatGroup(host, "Layout");
590+
const layoutGroup = host.querySelector('[data-flat-group-open="true"]');
591+
if (!layoutGroup) throw new Error("expected the Layout group to be open");
592+
593+
const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(
594+
(el) => el.querySelector("span")?.textContent === "X",
595+
);
596+
if (!xRow) throw new Error("expected an X row");
597+
const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');
598+
if (!gutter) throw new Error("expected a keyframe gutter on the X row");
599+
const buttons = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button"));
600+
const [prevArrow, , nextArrow] = buttons;
601+
if (!prevArrow || !nextArrow) throw new Error("expected prev/next arrow buttons");
602+
// At the 50% keyframe (t=3.5), prev should target the 0% keyframe
603+
// (absolute t=2) and next should target the 100% keyframe (absolute
604+
// t=5) — both only resolvable once currentPct agrees with elStart=2/
605+
// elDuration=3, the same basis the seek fix already uses.
606+
expect(prevArrow.disabled).toBe(false);
607+
act(() => prevArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));
608+
expect(onSeekToTime).toHaveBeenLastCalledWith(2);
609+
610+
expect(nextArrow.disabled).toBe(false);
611+
act(() => nextArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));
612+
expect(onSeekToTime).toHaveBeenLastCalledWith(5);
613+
act(() => root.unmount());
614+
},
615+
RENDER_TIMEOUT_MS,
616+
);
617+
});

‎packages/studio/src/components/editor/PropertyPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
293293
commitManualRotation={commitManualRotation}
294294
gsapAnimId={gsapAnimId}
295295
navKeyframes={navKeyframes}
296-
currentPct={currentPct}
296+
currentTime={currentTime}
297297
animIdForProp={animIdForProp}
298298
gsapRuntimeValues={gsap3dValues}
299299
elStart={elStart}

‎packages/studio/src/components/editor/PropertyPanelFlat.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function PropertyPanelFlat({
9494
commitManualRotation,
9595
gsapAnimId,
9696
navKeyframes,
97-
currentPct,
97+
currentTime,
9898
animIdForProp,
9999
gsapRuntimeValues,
100100
// Renamed: PropertyPanel.tsx still computes/passes these for its own legacy
@@ -186,7 +186,6 @@ export function PropertyPanelFlat({
186186
| "commitManualRotation"
187187
| "gsapAnimId"
188188
| "navKeyframes"
189-
| "currentPct"
190189
| "animIdForProp"
191190
| "gsapRuntimeValues"
192191
| "elStart"
@@ -207,6 +206,7 @@ export function PropertyPanelFlat({
207206
selectedElementId: string | null;
208207
clipboardCopied: boolean;
209208
onCopyElementInfo: () => void;
209+
currentTime: number;
210210
}) {
211211
// Lazy initializer: pick whichever group actually renders for this element
212212
// (Text if text-editable, else Style if style-editable, else none open) so a
@@ -236,6 +236,14 @@ export function PropertyPanelFlat({
236236
// Trivial percentage→time seek, derived here rather than threaded from
237237
// PropertyPanel (keeps that file under its 600-LOC gate).
238238
const seekFromKfPct = (pct: number) => onSeekToTime?.(elStart + (pct / 100) * elDuration);
239+
// Playhead position within the SAME corrected elStart/elDuration basis as
240+
// seekFromKfPct above — recomputed here (not threaded as `currentPct` from
241+
// PropertyPanel, which still derives it against its own naive basis for the
242+
// legacy panel) so KeyframeNavigation's diamond active-state and prev/next
243+
// arrow targeting agree with where a keyframe click actually seeks to
244+
// (follow-up fix to 684ec4e87, which corrected the seek basis but left this
245+
// one still naive).
246+
const currentPct = elDuration > 0 ? ((currentTime - elStart) / elDuration) * 100 : 0;
239247

240248
// Motion group double-gate — reproduces the legacy PropertyPanel gate exactly:
241249
// • Timing (sections.timing) shows via resolveEditingSections, same as today.

0 commit comments

Comments
 (0)