Skip to content

macOS engine: arrow keys in background Firefox take the held-focus route, so they move a rich editor's caret (#360) - #397

Merged
SSFSKIM merged 7 commits into
mainfrom
fix/360-firefox-nav-focus
Nov 17, 2026
Merged

SSFSKIM merged 7 commits into
mainfrom
fix/360-firefox-nav-focus

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What changes

On macOS, press_key of Left or Option+Left into a rich editor (contenteditable, a compose box) in a background Firefox window answered ok but left the caret where it was. The key reached the page and Gecko decoded the right command. But Firefox's caret-collapse commands check whether the editor's caret is enabled, and scroll instead when it isn't. The editor only enables its caret when it has logical focus, which a background window's editor doesn't.

Now, in a Firefox that doesn't believe it has focus, a key sequence that holds an arrow key (Left, Right, Up or Down, with any modifiers, Shift included) goes by route 3, the held activation with its guard that Command chords already take (rulings 1ea561bc:764 and 767). Route 3 gives the field logical focus before the key, which the page can see as a focus event. The answer stays what press_key promises, posted rather than confirmed, and no AX caret check is added (#394).

The rule lives in native/engine/Sources/Engine/Routes.swift (arrowKeyCodes, needsHeldActivation). Gecko is detected by the existing page-engine classification. Unchanged: foreground Firefox, every other app, and every non-arrow key. Home, End, Page Up and Page Down keep plain posting (see Limits).

Evidence

Tables are in docs/evidence/2026-11-17-firefox-nav-focus/README.md. Both runs judge against the fixture page's own DOM 1 s after the key, never against AX.

  • The spike, 44024467862: Firefox 159, 2,560/2,560 scorable.
    • Background rich collapse moves: 0/120, against 120/120 in plain fields and 240/240 in the foreground.
    • Cmd+Shift+Left extension: 40/40.
    • A focus prelude fixed every rich cell: 120/120.
    • Ruled out, all 0/80: window fields, the window event constructor, numeric-pad and Fn flags, private and combined-session event sources.
  • The qualification of the production path, 44047809532: Firefox 160, 1,600/1,600 scorable. The unmodified fix (f066023) ran against main c7eee72, with no forced route and no patch. The cells that cover the narrowed rule are Left, Option+Left, Cmd+Left and Cmd+Shift+Left in all four editors:
fix, background main, background (rich editors) fix, foreground
Left, Option+Left (rich) 80/80 0/80 80/80
Cmd+Left, Cmd+Shift+Left (rich) 80/80 80/80 (already route 3) 80/80
all four arrow cells, textarea and input 160/160 not run 160/160

Right, Up and Down weren't run. They take the same rule on the same route.

  • The watch: 0 observed target activations or target-over-cover raises in 501,913 samples, covering the guard, the call, the 1 s DOM sample and cleanup. Its gaps were p50 5.0 ms, p95 6.7 ms and max 176 ms (window-order samples up to 230 ms), so a flash shorter than that window can't be excluded. All 1,600 cleanups left the field's text, selection and scroll unchanged.
  • The price: a cold route-3 call costs 110/147 ms p50/p95, against 3/6 ms for a plain post; the guard is 104/142 ms of that. Command chords already pay the same. A call inside an existing hold wasn't measured.

Limits

  • Home, End, Page Up and Page Down are out of the rule (ruling 767). In the rich editors, main's plain posting already matched the foreground (160/160): on macOS those keys scroll and don't move the caret, so route 3 would add ~105 ms and a focus event for nothing. In a background textarea those four keys weren't run on main. The fix (which then still routed them) matched the foreground there 80/80. In a single-line input they do nothing, even in the foreground (160 attempts not applicable).
  • The answer is posted, not confirmed. Firefox's AX caret is stale in the background (macOS engine: background Firefox's caret never moves after typing, so a secret's read-back can't confirm (stated limit) #394), so nothing reads it back.
  • The page sees a focus event before the arrow key, which agent-cursor.md now says.

Verification

  • swift test (native/engine), after merging main cde920f: 1,216 tests, 0 failures, 1 skipped; KeyRouteTests 11/11. Node: docs-oracle, core-documentation and inventory 27/27. The new sentence is byte-identical in agent-cursor.md and its three copies.
  • Mutation check on the predicate: 8/8 mutants caught (dropping or inverting the Gecko condition, dropping Down, widening with Home or PageDown, ignoring focus, unmodified-only, first-press-only).
  • Review: doperpowers:reviewer-medium on c7eee72..f066023 came back correct. doperpowers:reviewer-low on the narrowing (c5afe3f..e15fd91) came back correct.
  • ci-gate on 8ad0df3, gates plugin, test and engine-swift: GREEN, https://github.com/SSFSKIM/cua/actions/runs/44062297679. The sandbox and browser-parity gates were not run: the change touches neither the sandbox nor the browser extension path.

Plugin 0.28.5.

Closes #360

Sminos-Session: cursor235#b93055dd (cua on macbook)

…held activation (refs #360)

In a background Firefox a rich editor keeps its caret disabled until it has
focus, so a posted Left, Option+Left or Cmd+Left scrolled instead of moving the
caret (#360's hosted spike, run 44024467862: 0 of 120; 120 of 120 after route
3's prelude). Following ruling 764, press_key now routes a sequence holding a
caret-navigation key (an arrow, Home, End, Page Up or Page Down, with any
modifiers) through the same held activation a Command chord takes, when the
app's page engine is Gecko and the app does not believe it has focus.

- Routes.swift: caretNavigationKeyCodes, isCaretNavigation and
  needsHeldActivation; pressKeyRoute takes the page engine.
- Input.swift: pressKey passes webAccessibility.pageEngine(app.appPath), the
  principal-class read #313 introduced.
- No editor role is read, and nothing reads the caret back: the answer is the
  posting's, since Firefox's AXSelectedTextRange is stale (#394).
- Foreground Firefox, other apps and every other key keep their route.

The native engine spec's Decision Log records the entry, and the Design's
route table names the exception.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…(refs #360)

The model's document gains one sentence closing the background-click
paragraph: in a Firefox window in the background, a pressKey of an arrow key,
Home, End, Page Up or Page Down first focuses the field the key goes to, which
the page can see as a focus event. The docs oracle's copy, the core
documentation test's copy, PROVENANCE.md and the surface inventory's new
Table 3 addition (2026-11-16, #360) carry it.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…n Log records the result (refs #360)

docs/evidence/2026-11-17-firefox-nav-focus/README.md records the two hosted
runs, linked rather than copied:

- Spike 44024467862 (Firefox 159.0): the cause, and the interventions it ruled
  out.
- Qualification 44047809532 (Firefox 160.0): the fix's own press_key against
  main.
  - Background passed 560 of 560 and foreground 560 of 560. Rich Left and
    Option+Left went from 0 of 80 on main to 80 of 80.
  - The watch observed no activation or raise in 501,913 samples. This is
    sampled evidence, not a no-flash guarantee.
  - Route 3 costs 110/147 ms p50/p95 cold, against 3/6 ms for the plain post.
  - The single-line input's Home/End/Page cells are N/A.

The Decision Log entry's "not yet measured" item now holds the measured
result and the route-3 cost.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…(refs #360)

Ruling 767 narrows #360's rule to Left, Right, Up and Down, with any modifiers
(Shift included). Home, End, Page Up and Page Down go back to 2' in a
background Firefox. Qualification run 44047809532 found that they scroll
rather than move the caret, and main's plain post already matched the
foreground for them in the rich editors (160 of 160).

- Routes.swift: caretNavigationKeyCodes becomes arrowKeyCodes (0x7B to 0x7E)
  and isCaretNavigation becomes isArrowKey.
- RouteTests: every arrow under eight modifier prefixes takes route 3 in
  background Firefox. Home, End and the page keys under the same prefixes
  keep 2', or route 3 as a Command chord. Both sets keep their route in
  foreground Firefox and in background Chrome and Safari.
- Decision Log: the entry becomes "#360's arrow keys". It names ruling 767,
  says which qualification cells cover the rule (Left, Option+Left, Cmd+Left
  and Cmd+Shift+Left in all four editors, 320 of 320), records that the four
  other keys were measured to work without it, and notes the one gap: a
  background textarea's Home, End and page keys by 2' were not run. The
  route-3 cost becomes item 7.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ly (refs #360)

Following ruling 767, the background paragraph's sentence now reads "a pressKey
of an arrow key, with or without modifiers, first focuses the field". The
oracle copy and the core-documentation test copy are byte-identical to it.
PROVENANCE.md and the surface inventory's #360 addition are updated to match.

The evidence README now names the narrowed set and ruling 767, and says which
qualification cells cover the rule. It also records the measurement that took
Home, End and the page keys out, and states that the watch's longest gap was
176 ms (p50 5.0 ms), so a flash shorter than that window cannot be excluded.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…#360)

Kept both sides of the three conflicts:

- PROVENANCE.md: main's agent-cursor.md row, which adds the sixth paragraph
  (#354), plus #360's clause on the background paragraph's last sentence and
  its description.
- docs-oracle.mjs: main's comment list, then #360's clause.
- surface inventory: #360's Table 3 addition (2026-11-16), then #354's
  amendment (2026-11-17, ruling 1ea561bc:765).

agent-cursor.md and its copies merged cleanly and stay byte-identical: #354's
typing paragraph and #360's arrow-key sentence are both in each one.

Sminos-Session: cursor235#b93055dd (cua on macbook)
Sminos-Session: cursor235#b93055dd (cua on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T10:26:16.702480Z 8ad0df3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SSFSKIM
SSFSKIM merged commit 4a3e26e into main Nov 17, 2026
6 checks passed
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.

Engine: in background Firefox, Left and Option+Left in a contenteditable have no effect, yet keypress answers success

1 participant