Skip to content

fix(studio): a drag pressed as a sealed preview takes the keyboard is no longer dropped - #9107

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/held-press-frame-focus
Nov 29, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/held-press-frame-focus

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A drag pressed in a sealed preview is no longer dropped when the preview takes the keyboard just after the press. Studio cancels a held drag when its window loses focus. A sealed preview's frame takes keyboard focus after a save, which blurs Studio's window although the person never left it. When that focus move landed just after a press, the press was cancelled: the box never followed the pointer and nothing was saved.

  • Gate: unchanged at 40 behaviours, all with a test. This removes the sealed-only failure of the bench case seqfastkeys-none-px-r0-root-z100, which failed 2 of its 3 sealed runs in the merge queue and dropped pull requests that changed sealed preview paths.

Why

The sealed preview may only become the default once it behaves as the unsealed one does. This case passes unsealed every time and failed sealed on a busy machine. On an idle machine it passed sealed 30 of 30; with the machine's CPUs kept busy it failed about 2 runs in 10, always on the third drag of the sequence (drag, add a key, seek, drag, seek, drag).

Related work

Follow-up to #9068 and #9089 (the sealed edit accuracy run and its gate).

How

  • useHeldGestureCancel.ts: a window blur cancels a held gesture only when focus has not moved into a frame on the page. focusMovedIntoAFrameOnThePage follows the focused element through open shadow roots, since the preview's frame sits inside the player's.

  • Why there: the canvas keyboard asks the frame to take focus when Studio arms it, decided when the request is sent. The frame applies it when the request arrives, which on a busy machine can be after the next press has started. The other focus paths already check for a held press at the moment they focus. Escape, a hidden tab and focus leaving the page still cancel as before.

  • Not changed: the colour grading controls (propertyPanelColorGradingSection.tsx, propertyPanelFlatColorGradingAccessory.tsx) and the beat strip (BeatStrip.tsx) also release a drag on a window blur. A frame taking focus during one of those drags would release it the same way; I have not reproduced that, so they are left for a follow-up with its own test. The Shift tracking (useTimelineShiftModifier.ts) is right to reset when focus moves into the frame.

Test plan

  • fails without the fix: "focus entering a frame on the page > keeps a held drag, which still lands where it is let go" (packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsx) fails with the old blur listener: the drag saves nothing. It also fails with the shadow root walk removed.

  • gestureHoldsPreviewReload, useSealedCanvasKeys.sealed, DomEditOverlay, editorGesturesExports, shiftDragAxisLock, selectionHandlesRideTheBox and sealedRawDragStep tests: 137 of 137, 3 runs in a row. tsc --noEmit in packages/studio: exit 0. oxlint and oxfmt: clean.

  • Edit accuracy bench, sealed build, the case alone, with the machine's CPUs kept busy: before, 2 of 9, 2 of 11 and 2 of 13 runs failed; after, 30 of 30 passed, at load averages between 2 and 14 on 4 cores. resize-keys-px-r0-nested-z100-on, the other sealed case that failed in the same merge queue run: 15 of 15 passed after the fix (not measured before it).

  • A probe of the failing runs logged the window's blur 4 ms after the third press began waiting, with the press held, the page still focused and focus in the preview player; the press was dropped by that cancel.

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

No visible change

The sealed preview is not on by default. In a sealed preview, a drag started just after a save now moves and saves as it does unsealed.

… no longer dropped

The sealed frame taking keyboard focus blurs Studio's window, and the held
gesture cancel read that as the person leaving the window. A blur whose
focus went into a frame on the page now leaves the press held.
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 57 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5f6d704. useHeldGestureCancel.ts read whole; the test file read as its hunk.

  • The body carries a fails without the fix: line naming "focus entering a frame on the page > keeps a held drag, which still lands where it is let go", and that test is in the diff. Reading it against the old listener: the window blur it dispatches would call cancel directly, so the drag would save nothing. It puts the frame inside an open shadow root, so it also covers the walk.
  • The blur listener is added and removed as the same function, so the unmount cleanup still matches.
  • Escape and a hidden tab still cancel through their own listeners, unchanged.

Note, not blocking: once focus sits in the frame the page's window is already blurred, so if the person then leaves the app with the press still held (switching windows, not tabs), no further blur reaches this listener and the press stays held until the pointer is released. Before this change the earlier blur would have ended it. Tab switches are still covered by the visibility listener. Worth a line in the follow-up you already plan for the other blur-released drags.

Not run: no install on this box; the tests and the bench numbers in the body are the author's.

Need: yes, measured 2 in 10 under load · Size: +9/-2 source, right · Reuse: n/a · Simpler: no · Structure: fix sits at the one listener
Risk: low; narrows one cancel path only.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 02c5a33 Nov 29, 2026
84 checks passed
@miguel-heygen
miguel-heygen deleted the fix/held-press-frame-focus branch November 29, 2026 20:18
miguel-heygen added a commit that referenced this pull request Nov 29, 2026
Main has #9107 as a squash with the helper local to useHeldGestureCancel.ts;
this branch moves it to utils/focusMovedIntoAFrame.ts, so the merge drops the
local copy that would otherwise sit beside the import.
This was referenced Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants