Fix native selection breaking caret navigation in focus mode editable content #20581
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
jcsteh
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+spaceleaves the caret stuck: pressingdownArrowdoes not move it and NVDA re-reports the line it started on.The reproduction from #19075, using the sample from the
test_i7562system test:1. Enable native selection mode with
NVDA+shift+f10.2. Open the following markup, e.g. as a
data:text/html,URL:3. Force focus mode with
NVDA+space.4. Press
downArrowfrom "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:
BrowseModeDocumentTreeInterceptorgains acollapseAppSelectionmethod, alongside the existingupdateAppSelectionandclearAppSelection. 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 asetFocus()on an element that is alreadydocument.activeElement.NVDA was reaching that state constantly.
Gecko_ia2_TextInfo._setSelectionOffsetspushes the browse mode selection to the application on every caret movement in both browse and focus mode, and for a collapsed caret it calledclearAppSelection.Three changes address this.
_setSelectionOffsetsnow 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.updateAppSelectionexpresses a collapsed range as a degenerateIA2TextSelection, whose end matches its start, rather than asSetSelections(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 newcollapseAppSelectionthrough_setAppSelection. When the caret position cannot be resolved, which happens when expanding byUNIT_CHARACTERyields no fields, the native selection is left unchanged rather than cleared, so a caret the browser already has survives.BrowseModeDocumentTreeInterceptor._set_disableAutoPassThroughsyncs 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_passThroughbecauseevent_gainFocussetspassThroughbefore 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_disableAutoPassThroughonly fires for an explicitNVDA+space, next to the existing_focusLastFocusableObjectcall that already syncs the focus to the browse mode cursor for the same reason.As a result
clearAppSelectionis 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 callscollapseAppSelection, 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_focusModeCaretMovementtochromeTests, which istest_i7562with native selection mode enabled first. Before this change all threedownArrowassertions fail, as each one reports "before".Known issues with pull request:
collapseAppSelectionraisesNotImplementedErrorin 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:
- Change log entry
- User Documentation
- Developer / Technical Documentation
- Context sensitive help for GUI changes
- Unit tests
- System (end to end) tests
- Manual testing
- Speech
- Braille
- Low Vision
- Different web browsers
- Localization in other languages / culture than English