Repository navigation
feat(studio): handle canvas Delete and arrow-key nudge in opaque preview runtime - #8935
Conversation
Edit accuracy: accurate 273 (base branch 271), smooth 59 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) |
# Conflicts: # packages/core/src/runtime/editingAgent.test.ts # packages/core/src/runtime/editingAgent.ts # packages/core/src/runtime/editingPort.test.ts # packages/core/src/runtime/editingPort.ts # packages/studio/src/components/editor/useDomEditNudge.ts
jerry-heygen
left a comment
There was a problem hiding this comment.
Reviewed 894c6ed2. Three cases need fixes before approval:
- Backspace can delete a clip instead of resetting its keyframes. It is the default binding for both actions. Studio’s dispatcher checks Reset Keyframes first (
appHotkeysDispatch.ts:256), but the frame arms Backspace for deletion whenever no individual keyframe is selected (useSealedCanvasKeys.ts:151). A selected clip can have resettable keyframes even when none is individually selected. Leave the overlapping combo with Studio unless Studio has already determined that Reset Keyframes cannot handle it. - The first nudge can be counted twice on a GSAP clip when the gesture read-ahead is cold.
canvasKeys.ts:332draws before notifying Studio. On a cache miss,useDomEditNudge.ts:412asks the frame for gesture-start values after that draw, so the member can use the already-nudged GSAP position as its baseline and then applytotalDx/totalDyagain. Carry the pre-draw baseline across the port (or fall back to the Studio path when it is unavailable). Cover a cold-cache GSAP nudge and verify the position is the same before and after save/reload. - A detached clip can be left with neither a save nor a rollback.
useSealedCanvasKeys.ts:192ignores the action after the canvas hold is lost, and cleanup at line 285 removes the listener before disarming. If the user leaves the canvas before Studio receives the Delete notification, the old frame can stay visible with the clip missing even though nothing was saved. The disarm path clears the arm but does not restore pending deletes. Make every pending Delete settle on the original frame, including when focus or selection changes before the action is accepted. Preserve deletes that Studio already accepted and is saving.
All 23 changed files match the exact test merge. The browser checks in the PR description are author-reported; I did not rerun them. The earlier edit-accuracy comment predates this head.
— Jerrai (pr-review)
…once Studio arms them
|
Stacked on #8946 (the core half). Review this PR for the Studio files plus the one-line Head While this PR's base is #8946's branch, |
jerry-heygen
left a comment
There was a problem hiding this comment.
Reviewed e151cd8a against the core PR’s head a50f7d12. The 12 files in this Studio stack match the exact test merge, and the integrated source tree is unchanged from 894c6ed2. The earlier Studio shards, runtime contract, timeline viewport, and edit-accuracy jobs passed on that tree against main. I did not rerun the browser checks.
The three blockers are still in the Studio half:
useSealedCanvasKeys.ts:151still arms Backspace as clip Delete before Studio can decide whether it should reset the selected clip’s keyframes. Leave the overlapping shortcut with Studio unless reset has already been ruled out.useDomEditNudge.ts:412still reads the GSAP baseline after the frame has drawn the first step when no cached start is available. Use a pre-draw baseline on that path, or keep the nudge in Studio when it lacks one.useSealedCanvasKeys.ts:192and:285still drop or unsubscribe from a pending Delete on focus loss without ensuring the frame settles it. A clip can disappear from the preview without a save or rollback. Keep settlement attached to the original frame until Studio has accepted or rejected the action.
This verdict covers #8935’s Studio integration, not #8946 on its own.
— Jerrai (pr-review)
…s first draw Studio's first nudge on a cold read now uses this start, so a GSAP clip is not moved twice.
…d settle every delete Backspace stays with Studio while Reset Keyframes may claim it. A Delete no canvas session takes is rolled back. A cold first nudge on a GSAP clip starts from the frame's pre-draw position.
|
All three blockers are fixed at 1. Backspace and Reset Keyframes. The frame no longer arms a Delete combo that equals the Reset Keyframes binding while reset may claim it. "May claim" means the selected clip has keyframes, which is the condition the dispatcher checks before calling reset. That condition now has one owner, 2. Cold first nudge on a GSAP clip. Each nudge step now carries 3. A pending Delete with no save and no rollback. Canvas-key actions now go through one listener per frame load instead of one per arm session. A Delete event that arrives while no session is active is rolled back on the frame that sent it. That covers an event arriving after cleanup, after the hold was lost, or for an old revision. Deletes Studio already took keep their own commit or rollback through Checked: the sealed canvas keys suite, 7 tests; it, the nudge, hotkey, preview-channel and sealed-keyboard suites (11 files, 167 tests), 3 runs in a row; core editing, port and agent suites (31 files, 561 tests); |
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at 11db2e22, stacked on #8946 at fe328900. The overlapping Backspace shortcut stays with Studio when Reset Keyframes can claim it. Cold GSAP nudges now carry the position from before the first draw, so Studio saves the step once. A Delete that the canvas session no longer accepts is rolled back by the listener attached to that frame load. The added tests cover all three behaviors.
All 13 files in this PR match the exact stacked test merge. The preview-regression workflow passed; other hosted checks were still running at review time. I did not rerun the browsers. This verdict covers the Studio stack at these two revisions, not a standalone approval of #8946.
— Jerrai (pr-review)
…he load-time shield arms A Delete pressed while armed saves even when it lands after the canvas session ends. Arming no longer installs the key shield, so same-origin frames are never shielded. The shield stays the first key listener. Unarmed, it lets keys through as main does.
|
At Same-origin previews and the arm path. Arming no longer installs the key shield. Forwarded twice, or forwarded and deleted. That needed the shield to be added after the agent's key watch. Only the arm path did that, and it no longer installs anything. The load-time shield is in place before the agent starts, so it is always the first key listener. While armed, it stops the key before the key watch sees it. Arming with nothing to do. While unarmed, the shield now returns before stopping anything. Keys reach the page and the agent's key watch exactly as they do on Delete when focus moves before Studio receives it. At Checked: core editing, port and agent suites (31 files, 563 tests); the Studio sealed, nudge, hotkey, preview-channel and sealed-keyboard suites (168 tests), 3 runs in a row; |
jerry-heygen
left a comment
There was a problem hiding this comment.
Changes requested at e96e1985, stacked on #8946 at fe328900. A delayed Delete can save the wrong clip group. useSealedCanvasKeys.ts:261–264 routes the frame’s action to the arm that received the key, but runDeleteAction passes only that arm’s primary selection and expandGroup: true. The save handler in useDomEditSession.ts:321 expands against the current group, not the group whose handles the frame removed. If Delete removes A+B in the frame and the selection changes to C+D before Studio handles the message, Studio can save the deletion of C+D instead.
Bind the save to the members for this arm and the handles that the frame actually removed, or roll back when they cannot be matched. Please cover a delayed group Delete followed by a different selection; the single-selection focus-loss regression doesn’t cover it.
All 16 changed files match the stacked test merge. Preview regression passed; the red Comments job is a separate comment-density check. I did not run the browser, and this is not a verdict on #8946 itself.
— Jerrai (pr-review)
Keeps both the canvas-key and stage-act request kinds and push listeners. The editing port's push handling becomes a table so both fit under the complexity gate.
…d, not the group selected since The canvas Delete passes the arm's members for the handles the frame removed. It rolls back when any removed handle has no member. Also cuts two comments the ratchet flagged.
|
Fixed at Each arm keeps its Delete members keyed by the handle it sent to the frame. When the frame's Delete arrives, every handle in it, which is the outermost set the frame actually detached, is mapped back to that arm's member. Studio's delete gets those members explicitly through a new Test: This head also has Checked: the sealed canvas keys suite (9 tests), 3 runs in a row; the Studio sealed, nudge, hotkey, delete-members, dom-edit-session, preview-channel and sealed-keyboard suites (193 tests), 3 runs in a row; core editing, port and agent suites (598 tests); |
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at e3cce12a, stacked on #8946 at e83c3e00. A delayed Delete now maps the handles the frame actually detached back to the members saved for that keyboard session. Studio persists that explicit list instead of expanding the current selection, and rolls back if a handle cannot be matched. The regression deletes A+B, switches to C+D before Studio gets the notification, and checks that only A+B are saved as deleted.
All 17 changed files match the stacked test merge. The hosted Comments and preview-regression workflows passed; other hosted workflows were still in progress when checked. I did not run a browser, and this is not a standalone verdict on #8946.
— Jerrai (pr-review)
The base branch was changed.
# Conflicts: # packages/core/src/runtime/editing/canvasKeys.test.ts # packages/core/src/runtime/editing/canvasKeys.ts # packages/core/src/runtime/editingAgent.ts
jerry-heygen
left a comment
There was a problem hiding this comment.
Approved at ccd9a3ac against main. All 17 changed files and their patches match the stacked review after #8946 landed. A delayed Delete still saves the members the frame actually detached, not the selection Studio happens to show when it receives the event. An unknown handle still rolls back rather than saving a partial deletion.
The hosted Studio preview routing regression and parity check ran and passed at this head. Other hosted checks were still running; I did not independently run a browser.
— Jerrai (pr-review)
Summary
In opaque-origin previews (
origin: "null"), canvas Delete and arrow-key nudge previously routed from Studio's parent window over theMessagePortto the preview frame, adding cross-frame latency before the first frame painted in Firefox and WebKit.This PR moves canvas-selected Delete and arrow-key nudge into the preview runtime while keeping Studio as the single owner of persistence, undo history, rollback, and timeline-focused shortcuts:
sealedFrameKeyboard.tsadds a dedicated canvas focus hold (holdSealedCanvasKeyboard/hasSealedCanvasKeyboardHold) alongside the inline-text hold.useSealedCanvasKeys.ts, wired inDomEditOverlay.tsx) acquires the canvas hold and focuses the preview iframe so trusted key events arrive directly in the frame.[data-studio-timeline]), inspector, dialogs, or inputs releases the hold and disarms the runtime. Canvas-selected Delete and nudge run in-frame; timeline-focused Delete keeps Studio's existing path unchanged.packages/core/src/runtime/editing/canvasKeys.tsinstalls capture-phasewindowlisteners (keydown,keyup,keypress,beforeinput,input) during top-level evaluation ofentry.ts(before any composition scripts run), using native references captured at evaluation time.isTrustedevents are handled or forwarded; synthetic/untrusted events are ignored.isActiveTextEditTargetintextEdit.ts) are carved out so typing, caret movement, Enter, and Escape continue to work normally. Outside active Studio text edits,stopImmediatePropagationprevents composition listeners from seeing Studio keystrokes.MessagePort(onKey), withpreventDefaultscoped to Studio's configured shortcut map (getStudioKeys()+Escape) so browser shortcuts (Cmd+R,Cmd+W,Cmd+T,Cmd+L) stay intact.arm-canvas-keys(automatically disarmed when selection clears, read-only, playback starts, inline text edit opens, or keyframes/automation range are selected).actionId), clearsdeleteHandlesso a rapid second Delete cannot double-fire, and postscanvas-key-action. Studio runs its existing delete persistence path (skipping redundantremove-elementsRPCs vianoteFrameRemovedHandles), then sendsresolve-canvas-key-action(commitorrollbackto restore detached elements in their original DOM order).totalDx/totalDysynchronously across rapid key-repeat presses, draws immediately viaeditingDraft.ts(drawDrafts, supporting both CSStranslateand GSAP position routes viagsapPosition), and postscanvas-key-action. Studio joins/opensuseDomEditNudge's debounced commit session (recording the runtime-drawn draft vianoteFrameDrawnDraftso zero redundantdraftRPCs are echoed) and owns debounce, save, history, and rollback.installPreviewKeyShieldruns only whenmarkedForStudio(document) && !capturePageIn(document) && window.parent !== windowand never in export/render mode (__HF_EXPORT_RENDER_SEEK_CONFIG), standalone builds, capture frames, or third-party embeds.Before
Selected canvas element in an opaque-origin preview before pressing 4x
Shift+ArrowRight:After
Same element after 4x
Shift+ArrowRight(+40 px, drawn immediately in-frame with selection chrome synced and 0 composition key events seen):Real-app browser verification (sealed
origin: "null")Verified in real Studio across headless Firefox 161, Chrome 155 (
IsolateSandboxedIframes), and WebKit with composition capture-phasekeydownlisteners installed on bothwindowanddocument:originShift+ArrowRightdeltaSpaceforwardedDeleteimmediate + persisted"null"<hyperframes-player>-><iframe>+40 px(549.93 -> 589.93)2/2true/true0([])"null"<hyperframes-player>-><iframe>+40 px(549.93 -> 589.93)2/2true/true0([])"null"<hyperframes-player>-><iframe>+40 px(549.93 -> 589.93)2/2true/true0([])Verification
packages/core/src/runtime/editing/canvasKeys.test.ts(5: capture-first shield + untrusted ignored + film input blocked, rapid repeat Arrow nudges across translate & GSAP, rapid second Delete whileactionIdis in-flight + rollback DOM order restore, inline-text carve-out + Studio shortcut forwarding + browser shortcut passthrough, not-in-render/capture/unmarked guard)packages/core/src/runtime/editingAgent.test.ts(190)packages/core/src/runtime/editingPort.test.ts(13)packages/core/src/runtime/entry.test.ts(64)packages/studio/src/components/editor/useSealedCanvasKeys.sealed.test.ts(4: canvas vs timeline focus ownership, in-frame Delete + persist rollback restore, rapid repeat Arrow nudges with single debounced commit & zero redundant draft echo, forwarded shortcuts gated on canvas hold + keyframe selection disarming Delete)useDomEditNudge.test.tsx,useDomEditNudge.sealed.test.tsx,sealedFrameKeyboard.test.ts,useAppHotkeys.previewForwarding.test.tsx,useTimelineDeleteOps.test.tsx,useElementLifecycleOps.multiDelete.test.tsx,usePlaybackKeyboard.test.tspackages/engine: 217/223 files (3767 tests) passed, including all browser render & motion-blur tests (the 5 failed files are pre-existing FFmpeg 7.0.2 static binary SIGSEGVs on local MPEG-TS fixtures).packages/producer: 123/124 vitest unit files (1632 tests, 1 same local FFmpeg MPEG-TS SIGSEGV) + all bun unit tests passed.oxfmt,oxlint(0 warnings, 0 errors),tsc --noEmit(core,core:runtime,studio),fallow audit --base origin/main --fail-on-issues(0 dead code, 0 complexity),comment-ratchet.mjs,check-comment-citations.mjs, andfilesize(DomEditOverlay.tsx= 596 lines <= 600) passed.