← Back to Pull requests

Fix native selection breaking caret navigation in focus mode editable content #20581

Closed
unknown closed this pull request without merging on Aug 10, 2026 04:33 UTC
View on GitHub
unknown unknown commented on Jul 28, 2026 21:43 UTC
Author

Link to issue number:

Closes #19075
Closes #18028

Summary of the issue:

With Native selection mode enabled in Firefox or a Chromium based browser, forcing focus mode with NVDA+space leaves the caret stuck: pressing downArrow does not move it and NVDA re-reports the line it started on.

The reproduction from #19075, using the sample from the test_i7562 system test:

1. Enable native selection mode with NVDA+shift+f10.
2. Open the following markup, e.g. as a data:text/html, URL:

<div contenteditable="true"><p>before</p><ul><li>frogs</li><li>birds</li></ul><p>after</p></div>

3. Force focus mode with NVDA+space.
4. Press downArrow from "before". NVDA keeps saying "before".

The same cause is behind #18028, where typing in some Chromium edit fields with native selection mode enabled does not work.

Description of user facing changes:

In Firefox and Chromium based browsers with Native selection mode enabled, the caret can be moved normally in focus mode.

Disabling native selection mode no longer leaves the document without a caret, effectively breaking a caret in a contenteditable. The selection is collapsed to a caret instead of being removed.

Description of developer facing changes:

BrowseModeDocumentTreeInterceptor gains a collapseAppSelection method, alongside the existing updateAppSelection and clearAppSelection. It collapses the native selection in the application as it were a caret at the browse mode cursor. Implementations that support native selection mode should implement it.

Description of development approach:

Clearing the native selection is not a neutral no-op. In a document the native selection is the caret, so IAccessibleTextSelectionContainer::SetSelections(0, …) removes the caret rather than merely leaving nothing selected. The browser cannot repair this on its own, because Blink only places a caret in an editable on the focus transition into it. Once the element is already focused and the selection has been wiped, nothing recreates one: not key input, and not a setFocus() on an element that is already document.activeElement.

NVDA was reaching that state constantly. Gecko_ia2_TextInfo._setSelectionOffsets pushes the browse mode selection to the application on every caret movement in both browse and focus mode, and for a collapsed caret it called clearAppSelection.

Three changes address this.

_setSelectionOffsets now only pushes the selection to the application while browse mode is active. In focus mode the application owns the caret, and NVDA's browse mode selection still tracks it, so it is correct again as soon as browse mode returns.

updateAppSelection expresses a collapsed range as a degenerate IA2TextSelection, whose end matches its start, rather than as SetSelections(0, …). Syncing a collapsed browse mode caret now places a caret in the document instead of removing one. The range handling is shared with the new collapseAppSelection through _setAppSelection. When the caret position cannot be resolved, which happens when expanding by UNIT_CHARACTER yields no fields, the native selection is left unchanged rather than cleared, so a caret the browser already has survives.

BrowseModeDocumentTreeInterceptor._set_disableAutoPassThrough syncs the selection when the user manually switches to focus mode. That is needed because browse mode has usually already cleared the selection by then, so there is no caret left to inherit. This hook was chosen over _set_passThrough because event_gainFocus sets passThrough before it updates the browse mode selection, so hooking the latter would place the caret at the stale pre-focus position when tabbing or clicking into a field. _set_disableAutoPassThrough only fires for an explicit NVDA+space, next to the existing _focusLastFocusableObject call that already syncs the focus to the browse mode cursor for the same reason.

As a result clearAppSelection is reachable from one place only, a collapsed browse mode caret move, where NVDA owns navigation and the document does not need a caret. Turning native selection mode off now calls collapseAppSelection, which removes the highlight while leaving the document with a working caret. That path previously destroyed the caret too, which was invisible before this change because the caret was already gone.

Testing strategy:

Manually tested from source in Firefox and Chrome with the reproduction above as well as the one from #18028. With native selection mode enabled, focus mode arrow navigation moves through "before", "frogs", "birds" and "after", matching the behaviour with native selection mode disabled. Disabling native selection mode afterwards leaves the caret usable.

Intermediate versions were tested to confirm each part is needed. Restricting the selection push to browse mode is not sufficient on its own: the caret is still stuck, because browse mode cleared the selection before focus mode was entered. Placing the caret on the switch to focus mode is what makes the difference.

Added system test test_nativeSelectionMode_focusModeCaretMovement to chromeTests, which is test_i7562 with native selection mode enabled first. Before this change all three downArrow assertions fail, as each one reports "before".

Known issues with pull request:

collapseAppSelection raises NotImplementedError in the base class. No other browse mode implementation currently sets _nativeAppSelectionModeSupported, so nothing else needs it today, but a third party implementation would report a debug warning when native selection mode is turned off until it implements the method.

Code Review Checklist:

  • Documentation:

  • - Change log entry
    - User Documentation
    - Developer / Technical Documentation
    - Context sensitive help for GUI changes
  • Testing:

  • - Unit tests
    - System (end to end) tests
    - Manual testing
  • UX of all users considered:

  • - Speech
    - Braille
    - Low Vision
    - Different web browsers
    - Localization in other languages / culture than English
  • API is compatible with existing add-ons.

  • Security precautions taken.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: jcsteh Review duration: 17690m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #20581"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository