Fix: Clear selection after programmatic focus to prevent Firefox text selection (fixes #843)#844
Conversation
… selection bug (fixes #843)
oliverfoster
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #843
Fix
_refocusCurrentActiveElement(), callwindow.getSelection()?.removeAllRanges()immediately after the programmaticfocus()callTesting
_accessibility._isEnabled: trueinconfig.jsonTest in Chrome to confirm no regression.
JAWS regression check: The
_refocusCurrentActiveElement()method being modified was introduced in #697 to prevent JAWS from scrolling when its virtual cursor interacts with grouped elements.removeAllRanges()only affects browser text selection state, which JAWS does not use, so regression is unlikely - but if JAWS testing is available, verify focus behaviour onrole=groupelements after this change.Root Cause
PR #697 (v6.72.1) added
_refocusCurrentActiveElement()to handle a JAWS virtual cursor scrolling issue. This method calls.focus()programmatically on the previously-active element whenever focus unexpectedly returns tobody/html(via_onBlur).Firefox sets a persistent selection anchor when focus is assigned programmatically. Because
_onBlurfires betweenmousedownandmouseupon every click of non-focusable content, Firefox repositions the selection anchor on each click. The nextmousedownthen extends the selection from that anchor to the new click point.Calling
removeAllRanges()immediately afterfocus()clears the anchor beforemouseupcan use it - so no text is selected and there is no visible flash. JAWS is unaffected as it uses its own virtual cursor, not browser text selection state.Posted via collaboration with Claude Code