fix(uia): resolve selection retrieval failure with tabindex parent#1
Draft
fix(uia): resolve selection retrieval failure with tabindex parent#1
Conversation
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.
[WIP] tested, but not code reviewed
Description
This PR fixes an issue where text selection retrieval via UI Automation fails when the selected text resides within a parent element having
tabindex="0".Problem
In modern web browsers (Chrome/Edge), setting
tabindex="0"on a container element (like a<div>) causes it to receive UI Automation focus instead of the specific text node or the document root. Since these container elements often do not implement theTextPatterninterface (or delegate selection management to the document root), the previous implementation would fail to retrieve the selection, returning an empty result.Additionally, the
ElementFromPointstrategy would often target leaf nodes (like<span>) that also lackTextPatternsupport, missing the actual selection managed by ancestor nodes.Solution
TextPatternand contains the active selection.TryGetTextFromElement) to reduce code duplication and improve readability.ElementFromPointstrategy with the new walk-up logic to better handle mouse-based selections.Changes
SelectionHook::GetTextViaUIAutomationto include ancestor traversal loops.TryGetTextFromElementhelper for consistent pattern checking.Impact
This ensures reliable text selection retrieval in complex HTML structures involving
tabindexand nested elements, significantly improving compatibility with web-based applications.