Skip to content

UI Automation in Microsoft Word: Use move by sentence custom pattern when available instead of the legacy model#19367

Merged
seanbudd merged 12 commits intonvaccess:masterfrom
codeofdusk:t13517
Jan 16, 2026
Merged

UI Automation in Microsoft Word: Use move by sentence custom pattern when available instead of the legacy model#19367
seanbudd merged 12 commits intonvaccess:masterfrom
codeofdusk:t13517

Conversation

@codeofdusk
Copy link
Copy Markdown
Contributor

Link to issue number:

Closes #13517.

Summary of the issue:

NVDA exclusively uses Word's legacy object model for sentence navigation, even when UIA is enabled.

Description of how this pull request fixes the issue:

Added support for the UIA custom extension to move and expand by sentence in supported scenarios. The legacy implementation remains as a fallback on systems without remote ops support (Windows below 11/Cobalt platform) or older Office versions.

Testing strategy:

Moved by sentence in a large document and verified functionality.

Known issues with pull request:

None known

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.

Copilot AI review requested due to automatic review settings December 10, 2025 17:39
@codeofdusk codeofdusk requested a review from a team as a code owner December 10, 2025 17:39
@codeofdusk codeofdusk marked this pull request as draft December 10, 2025 17:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for UI Automation remote operations to enable sentence navigation in Microsoft Word when the legacy object model is unavailable. The implementation uses Word's custom UIA extension patterns (MoveBySentence and ExpandToEnclosingSentence) when available on Windows 11 with remote operations support, falling back to the existing legacy object model approach otherwise.

  • Adds a new function msWord_moveTextRangeBySentence in UIAHandler/remote.py to handle sentence navigation via UIA remote operations
  • Refactors _caretMoveBySentenceHelper in Word document handling to prefer UIA remote operations, with legacy fallback
  • Extracts common pattern retrieval logic into a reusable helper function _msWord_remote_getExtendedTextRangePattern

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
user_docs/en/changes.md Adds changelog entry documenting the new sentence navigation capability in Word with UIA on Windows 11
source/UIAHandler/remote.py Implements msWord_moveTextRangeBySentence function using Word UIA custom patterns and extracts _msWord_remote_getExtendedTextRangePattern helper function
source/NVDAObjects/UIA/wordDocument.py Updates _caretMoveBySentenceHelper to attempt UIA remote sentence navigation first before falling back to legacy object model
Comments suppressed due to low confidence (2)

source/NVDAObjects/UIA/wordDocument.py:675

  • The exc_info=True parameter is redundant when using log.exception(). The log.exception() method automatically includes exception information, so explicitly passing exc_info=True is unnecessary. Consider removing this parameter.
	TextInfo = WordDocumentTextInfo

	def _get_mathMl(self):
		try:

source/NVDAObjects/UIA/wordDocument.py:653

  • Typo in comment: "overide" should be "override".
				pos,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codeofdusk codeofdusk force-pushed the t13517 branch 7 times, most recently from f82061b to 150d7ff Compare December 10, 2025 18:02
@codeofdusk codeofdusk marked this pull request as ready for review December 10, 2025 18:02
Comment thread source/UIAHandler/remote.py Outdated
Comment thread source/UIAHandler/remote.py Outdated
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Dec 16, 2025
Comment thread user_docs/en/changes.md Outdated
@CyrilleB79
Copy link
Copy Markdown
Contributor

@codeofdusk, it may be interesting to test #9002, in case this PR changes something or even fixes it.

Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
Comment thread source/NVDAObjects/UIA/wordDocument.py
Comment thread source/UIAHandler/remote.py Outdated
codeofdusk and others added 5 commits December 29, 2025 19:30
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
Copy link
Copy Markdown
Member

@seanbudd seanbudd left a comment

Choose a reason for hiding this comment

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

Thanks @codeofdusk

Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
@seanbudd seanbudd enabled auto-merge (squash) January 16, 2026 05:47
@seanbudd seanbudd merged commit 570d760 into nvaccess:master Jan 16, 2026
39 checks passed
@github-actions github-actions Bot added this to the 2026.2 milestone Jan 16, 2026
tareh7z pushed a commit to tareh7z/nvda that referenced this pull request Feb 16, 2026
…when available instead of the legacy model (nvaccess#19367)

<!-- Please read and fill in the following template, for an explanation
of the sections see:

https://github.com/nvaccess/nvda/blob/master/projectDocs/dev/githubPullRequestTemplateExplanationAndExamples.md
Please also note that the NVDA project has a Citizen and Contributor
Code of Conduct which can be found at
https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV
Access expects that all contributors and other community members read
and abide by the rules set out in this document while participating or
contributing to this project. This includes creating or commenting on
issues and pull requests.

Please initially open PRs as a draft.
When you would like a review, mark the PR as "ready for review".
See
https://github.com/nvaccess/nvda/blob/master/.github/CONTRIBUTING.md.
-->

### Link to issue number:
Closes nvaccess#13517.

### Summary of the issue:
NVDA exclusively uses Word's legacy object model for sentence
navigation, even when UIA is enabled.

### Description of how this pull request fixes the issue:
Added support for the [UIA custom
extension](https://docs.microsoft.com/en-gb/office/uia/word/wordcustompatterns)
to move and expand by sentence in supported scenarios. The legacy
implementation remains as a fallback on systems without remote ops
support (Windows below 11/Cobalt platform) or older Office versions.

### Testing strategy:
Moved by sentence in a large document and verified functionality.
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.

Use custom extensions to move by sentence in Microsoft Word controls

6 participants