feat(studio): mirror canvas z-order actions into timeline lanes (track order = default paint order)#2380
feat(studio): mirror canvas z-order actions into timeline lanes (track order = default paint order)#2380ukimsanov wants to merge 5 commits into
Conversation
…e z overrides Track order = default paint order; authored z = advanced override. - timelineZMirror.ts: pure resolver mapping a successful z-menu action to a timeline lane move — closest track in the action's direction that is free over the clip's whole span, else a new lane adjacent to the crossed neighbor; temporal-overlap scope (default pending product sign-off, see module doc); visual zone only; same-file reference scoping; persistTrack via the shared authored-space rules. null for non-clips (menu stays z-only) and at-extreme/no-overlap cases. - useCanvasZOrderTimelineMirror.ts: after the z commit resolves, the mirror persists the lane move through the same machinery as a timeline lane drag (optimistic store update, authoredTrack refresh, rollback); inserts reuse commitTrackInsert's renumber via a shared buildTrackInsertEdits core. Both writes share one coalesce key (zReorderCoalesceKey) and fold into ONE undo entry (test proves it over the real history reducer). The mirror never triggers the lane->z stacking sync, so it cannot fight the z values the action just set. - timelineZOverride.ts + TimelineClip badge: clips whose paint order contradicts lane order among temporally-overlapping same-context visual neighbors (laneIsAbove XOR paintsAbove, the stacking-sync predicates) show a 'z' badge — authored z overrides are surfaced instead of silently disagreeing with the timeline. - Timeline.tsx track derivations extracted to useTimelineTrackDerivations (600-line cap).
…s slow persists Live verification caught the z write and the mirrored lane write splitting into two undo entries: the mirror runs after the z persist's server round trip, which exceeds editHistory's default 300ms coalesce window under real latency (the unit test's deterministic clock sat inside it). zReorderCoalesceKey now mints a per-gesture-unique key (monotonic seq, the laneChangeGestureSeq precedent) and both records carry coalesceMs Infinity — distinct gestures can never merge, and one gesture always folds regardless of write latency. coalesceMs threaded through the persist chain alongside coalesceKey. Also hardens the existing lane-drag move->z fold, which had the same latent split. Fold test now simulates a 400ms gap (failed before the fix, passes after); a two-separate-gestures test asserts two entries.
…ack menu - Track-only batch moves (the z-mirror's lane hop and the insert renumber) skip the GSAP fallback round-trip and the preview reload entirely — the renderer never reads data-track-index, and the live DOM patch + optimistic store update cover the UI. Mixed batches keep current behavior. Kills the canvas blink on mirrored Bring/Send actions (live-verified: an iframe-scoped marker survives the whole gesture). - The four z-order menu items get 16px stroke icons (single layer diamond + directional arrow for Forward/Backward; pierced two-layer stack for Front/Back); labels unchanged — they are the industry-standard names. - New track context menu on empty lane space: 'Close gap' (shifts the next clip and every clip after it on that lane left by the clicked gap's width; leading gaps count, so a single clip with empty space before it compacts to 0) and 'Close all gaps' (whole lane contiguous from 0). Pure gap math in timelineGaps.ts; persists through the drag path's atomic batch move (one undo per action); refuses when a clip that must shift is locked; items disable when there is nothing to close.
|
Follow-up commit from live feel-testing:
Full studio suite 2196 passing (same 18 environmental failures); all pre-commit gates green. |
…ssical z-menu order Timing edits that rewrote NO GSAP positions (gap closes and moves of selector-addressed caption clips, zero-delta batches, comps without a rewritable script) full-reloaded the preview — and the rerun-current-scripts attempt was wrong for real compositions: re-executing init-style scripts (three.js scenes, caption engines) is exactly the unsafe case, verified live by doubled init warnings and a fallback reload anyway. The correct observation: when mutated === false the existing __timelines are still valid — only the runtime's clip visibility windows are stale, and the live DOM timing attributes were already patched. So the no-mutation path now runs applySoftReloadFinalization only (seek + __hfForceTimelineRebind + manual-edits reapply), extracted from the soft-reload machinery — zero script execution. This also un-blinks comps with no GSAP script at all, which previously always remounted. Rewritten-script soft reloads, cannot-soft-reload, otherFileChanged, and mutation failures keep their existing behavior. gsapSoftReload's undo/redo restore section moved verbatim to gsapUndoRestore.ts for the 600-line cap. Also: z-order menu items reordered to the classical arrangement (Bring to Front, Bring Forward, Send Backward, Send to Back). Live-verified on a three.js-heavy composition: Close-all-gaps shifted 4 caption clips with correct cumulative amounts, the preview iframe was never remounted (marker survived), and one undo reverted everything.
|
Two more feel-test rounds (
Suite 2210 passing (same 18 environmental), all gates green. |
User-specified semantic: Bring Forward / Send Backward move the clip past EXACTLY ONE element. The mirror's lane target is now bounded by the next temporally-overlapping element beyond the crossed neighbor: a free lane strictly between the two is taken (closest to the neighbor), and when they are back-to-back a new track is inserted immediately beyond the crossed element — never past the second one. Previously the resolver took the closest free lane anywhere beyond the neighbor, which could carry the track past a second element while the z action only stepped past one — a track/paint contradiction our own zOverride badge would flag. Front/back keep whole-set semantics (past everything; back stays above the audio zone). End-to-end test pins the 3-stacked case through commitZMirrorLaneMove to the persisted renumbered tracks.
|
Final semantic correction from user review ( |
miguel-heygen
left a comment
There was a problem hiding this comment.
Requesting changes on the current head (bf09849). The decomposition and test effort are strong, but these verified correctness and persistence issues can leave Studio state or project files inconsistent:
timelineClipDragCommit.ts:404— mirror inserts normalize the full timeline and can persist track renumbers into unrelated composition files (and some layouts shift audio). Scope the insert candidate and writes to the selected source-file visual lane family.timelineZMirror.ts:118—sameSourceFileis treated as the stacking-context boundary. A file can contain multiple CSS stacking contexts; use the canonicalstackingContextIdpartition.useCanvasZOrderTimelineMirror.ts:76— the crossed-neighbor key omitsselectorIndex, so duplicate class selectors resolve to index 0 and can mirror against the wrong clip.timelineGaps.ts:86— gap compaction starts at absolute time 0 even for expanded children whose display time is parent-relative. This can move an expanded clip to the wrong display time and persist a different local time.PreviewOverlays.tsx:254— an unmatched/no-change z patch resolves successfully and still triggers the lane mirror. Return explicit match/persist status and mirror only after the selected z patch is durable.timelineTimingSync.ts:450— multi-clip gap closing performs sequential GSAP mutations. If a later mutation fails, earlier script rewrites remain on disk without the aggregate history fold. Make the mutation atomic or roll back all touched files.PreviewOverlays.tsx:254— z persistence and lane mirroring use separate queues. A second rapid gesture can write between the first gesture phases and overwrite file state; serialize the complete z-to-lane transaction.
Please add regression coverage for mixed source files/stacking contexts, duplicate selectors, expanded-lane origins, unmatched patches, late GSAP failure, and overlapping z gestures.
All current CI checks are green; these are behavioral cases not covered by the existing suite.
What
Implements the agreed model: track order = default paint order, authored z = advanced override. Canvas z-order menu actions (Bring to Front / Bring Forward / Send Backward / Send to Back) on a timeline clip now ALSO move the clip on the timeline — to the closest track beyond the element it crossed, in the action's direction, that is free over the clip's whole time span; when none is free, a new track is created adjacent to that element (the sanctioned insert renumber). Both writes fold into one undo entry. Clips whose authored z contradicts their lane order get a small "z" badge ("Paint order overridden — see Layers panel"), so overrides are surfaced instead of silently disagreeing with the timeline.
Design (the load-bearing decisions)
timelineZMirror.ts's module note.How
timelineZMirror.ts— pure resolver ({kind:"move", displayTrack, persistTrack} | {kind:"insert", insertRow} | null), reusingisLaneFree/timeRangesOverlapand the shared authored-space translation (authoredTrackForLane) — no duplicated machinery. 31 dedicated tests (span-freeness, zone boundary, sparse authored files, sub-comp scoping, determinism).useCanvasZOrderTimelineMirror.ts— runs after the z commit resolves; kind:"move" persists through the same path as a timeline lane drag (optimistic store update, authoredTrack refresh, rollback); kind:"insert" reusescommitTrackInsert's renumber via a sharedbuildTrackInsertEditscore. The mirror never triggers the lane→z stacking sync, so it cannot fight the z values the action just set (tested).zReorderCoalesceKeyis per-gesture-unique (monotonic seq) and both records carrycoalesceMs: Infinity— a gesture always folds regardless of persist latency, and distinct gestures can never merge. This also hardens the existing lane-drag move→z fold, which had the same latent >300ms split. The fold test simulates a 400ms gap (failed before, passes after).timelineZOverride.ts+TimelineClipbadge —laneIsAbove XOR paintsAboveamong temporally-overlapping same-context visual neighbors, using the exact stacking-sync predicates (exported, not copied).Test plan