Fix NVDA+K not recognizing links with nested elements#19428
Merged
SaschaCowley merged 9 commits intoJan 23, 2026
Merged
Conversation
When the caret is positioned on text inside nested elements (e.g. <strong>, <em>, <span> inside <a>), NVDA+K now correctly traverses up the parent hierarchy to find the enclosing link and report its URL. Changes: - Add parent hierarchy traversal (max 10 levels) to find enclosing links - Preserve special handling for graphics inside links (nvaccess#14779) - Add Sphinx-format docstring per NVDA coding standards
Tests cover: - Plain links - Links with nested <strong> elements - Links with nested <em> elements - Links with deeply nested elements (<strong><em><span>) - Image links (nvaccess#14779) - Non-link elements (should report 'Not a link')
SaschaCowley
left a comment
Member
There was a problem hiding this comment.
Just a small question regarding the tests, otherwise looks good
SaschaCowley
approved these changes
Jan 22, 2026
SaschaCowley
requested changes
Jan 22, 2026
SaschaCowley
left a comment
Member
There was a problem hiding this comment.
Please fix formatting errors by applying suggestions
Contributor
Author
|
Done! |
SaschaCowley
approved these changes
Jan 23, 2026
tareh7z
pushed a commit
to tareh7z/nvda
that referenced
this pull request
Feb 16, 2026
Fixes nvaccess#17363 ### Summary of the issue: Previously, the `NVDA+K` command failed to identify links when the caret was positioned on text wrapped in nested elements (e.g., `<strong>`, `<em>`, or `<span>`) within an `<a>` tag. This occurred because the command only checked the immediate object at the caret or its direct parent, missing links further up the hierarchy. ### Description of user facing changes: `NVDA+K` now correctly identifies and reports the destination of links even when the text at the caret position is formatted (e.g., bold or italicized) or contained within other nested elements. ### Description of developer facing changes: In `source/textInfos/__init__.py`: - Updated `_getLinkDataAtCaretPosition` to traverse up the object hierarchy (max 10 levels) to find an enclosing link if the current object is not one. - Added a docstring to `_getLinkDataAtCaretPosition`. - Refactored the logic to explicitly handle graphics inside links (preserving existing fix nvaccess#14779) before checking for general link ancestors. ### Description of development approach: The solution involves checking the ancestors of the object at the caret position. If the current object is not a link, the code iterates up the parent chain until a link is found or the traversal limit (10 levels) is reached. This ensures robust detection of enclosing links while preventing infinite loops in case of malformed object trees. ### Testing strategy: - Verified `NVDA+K` on an HTML test case with links containing nested `<strong>`, `<em>`, and `<span>` tags. - Verified that `NVDA+K` still works for simple links. - Verified regression testing for graphics inside links (as per nvaccess#14779). ### Known issues with pull request: None.
5 tasks
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.
Link to issue number:
Fixes #17363
Summary of the issue:
Previously, the
NVDA+Kcommand failed to identify links when the caret was positioned on text wrapped in nested elements (e.g.,<strong>,<em>, or<span>) within an<a>tag. This occurred because the command only checked the immediate object at the caret or its direct parent, missing links further up the hierarchy.Description of user facing changes:
NVDA+Know correctly identifies and reports the destination of links even when the text at the caret position is formatted (e.g., bold or italicized) or contained within other nested elements.Description of developer facing changes:
In
source/textInfos/__init__.py:_getLinkDataAtCaretPositionto traverse up the object hierarchy (max 10 levels) to find an enclosing link if the current object is not one._getLinkDataAtCaretPosition.Description of development approach:
The solution involves checking the ancestors of the object at the caret position. If the current object is not a link, the code iterates up the parent chain until a link is found or the traversal limit (10 levels) is reached. This ensures robust detection of enclosing links while preventing infinite loops in case of malformed object trees.
Testing strategy:
NVDA+Kon an HTML test case with links containing nested<strong>,<em>, and<span>tags.NVDA+Kstill works for simple links.Known issues with pull request:
None.
Code Review Checklist: