Skip to content

Fix NVDA+K not recognizing links with nested elements#19428

Merged
SaschaCowley merged 9 commits into
nvaccess:masterfrom
cary-rowen:fix/issue-17363-link-detection-nested-elements
Jan 23, 2026
Merged

Fix NVDA+K not recognizing links with nested elements#19428
SaschaCowley merged 9 commits into
nvaccess:masterfrom
cary-rowen:fix/issue-17363-link-detection-nested-elements

Conversation

@cary-rowen

Copy link
Copy Markdown
Contributor

Link to issue number:

Fixes #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 Chrome/Edge: NVDA unable to report the destination of various link types #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:

Known issues with pull request:

None.

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.

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
@cary-rowen cary-rowen requested a review from a team as a code owner January 10, 2026 08:54
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 SaschaCowley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small question regarding the tests, otherwise looks good

Comment thread tests/system/robot/chromeTests.py
Comment thread tests/system/robot/chromeTests.py
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Jan 12, 2026
Comment thread source/textInfos/__init__.py Outdated

@SaschaCowley SaschaCowley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix formatting errors by applying suggestions

@cary-rowen

Copy link
Copy Markdown
Contributor Author

Done!

@SaschaCowley SaschaCowley merged commit a7c0bff into nvaccess:master Jan 23, 2026
41 checks passed
@github-actions github-actions Bot added this to the 2026.2 milestone 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVDA Fails to Recognize Links with Embedded <strong> Tag Using NVDA+K Chrome/Edge: NVDA unable to report the destination of various link types

3 participants