Fix UIA text unit crash and Word sentence-nav boundary wraparound - #20498
Conversation
UIATextInfo.expand()/move() raised an uncaught KeyError for any NVDA text unit UIA has no mapping for (e.g. sentence), instead of the NotImplementedError browse mode already expects for graceful no-ops. Added UIAHandler.getUIAUnitFromNVDAUnit() to convert the lookup failure properly. Separately, Word's native MoveBySentence/ExpandToEnclosingSentence UIA extensions silently wrap around at document boundaries rather than stopping, which would teleport the caret to the opposite end of the document. Added a boundary guard to msWord_textRange_expandToEnclosingSentence and wired native sentence support into WordDocumentTextInfo.expand()/move() so browse mode gets real Word sentence navigation instead of a silent no-op. msWord_moveTextRangeBySentence is split into msWord_textRange_moveBySentence, msWord_textRange_moveEndpointBySentence, and msWord_textRange_expandToEnclosingSentence. As the old name has only ever shipped in 2026.2 betas, it is removed outright rather than kept as a deprecated alias. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@codeofdusk Could you please share your thoughts here? |
|
If there's no user facing changes, do we need to take this PR to beta? It seems complicated and risky. |
That is not correct. This fixes an issue where sentence nav wraps at the bottom of a document. So currently in Word, if you have a document with
The reason why I filed this against beta initially is that it changes the @seanbudd What would you suggest to limit the change to a minimum? E.g. making |
|
This looks alright to me. @seanbudd are you happy accepting this to beta this late? Note that it contains what would be API breaking changes if introduced in a future release. |
|
Yes, let's merge this |
Link to issue number:
Follow-up to #19367.
based on
betabecause it fixes a feature introduced in said branch that has not yet been released.Summary of the issue:
While wiring native Word sentence navigation into
WordDocumentTextInfo.expand()/move()forUNIT_SENTENCE(related to #20467), two issues surfaced:UIATextInfo.expand()/move()raise an uncaughtKeyErrorfor any NVDA text unit UIA has no mapping for, instead of aNotImplementedError, which is the contractTextInfo.expand()/move()callers rely on for a graceful no-op.UNIT_SENTENCEis one such unmapped unit, so callingexpand()/move()with it on a UIATextInfocrashed instead of raising cleanly.MoveBySentence/ExpandToEnclosingSentenceUIA extensions silently wrap around at document boundaries instead of stopping. Moving forward from the last sentence (or expanding a collapsed range at the very end of the document) teleports the range to the start of the document rather than staying put.Description of user facing changes:
alt+downArrow/alt+upArrow) at the start/end of a document now stops there instead of wrapping around to the opposite end.Description of developer facing changes:
UIAHandler.getUIAUnitFromNVDAUnit(), which raisesNotImplementedErrorinstead of letting aKeyErrorescapeNVDAUnitsToUIAUnitslookups.UIATextInfo.expand()/move()now use it. This is a general robustness fix for the UIATextInfoAPI, strictly spoken independent of sentence navigation but definitely a show stopper for Restore sentence as the default say all reading unit, with a setting to read by paragraph or line #20467. It feels more appropriate to fix this in the current PR instead of in Restore sentence as the default say all reading unit, with a setting to read by paragraph or line #20467.UIAHandler.remote.msWord_moveTextRangeBySentence()is split intomsWord_textRange_moveBySentence(),msWord_textRange_moveEndpointBySentence(), andmsWord_textRange_expandToEnclosingSentence().msWord_moveTextRangeBySentenceis UIA-remote-ops-internal API that has only ever shipped in 2026.2 betas (no stable release), and this branch targets beta, the rename drops the function outright rather than keeping a deprecated back-compat shim.Description of development approach:
WordDocumentTextInfo.expand()/move()forUNIT_SENTENCE. The sentence-navigation script now goes through thisTextInfoAPI instead of calling the remote op directly.UIAHandler.remote.msWord_textRange_expandToEnclosingSentence(): a collapsed range at the very end of the document is returned unchanged instead of being expanded to the first sentence in the document.Testing strategy:
getUIAUnitFromNVDAUnit()(mapped and unmapped units).alt+downArrow/alt+upArrow) at the start/end of a document stops instead of wrapping.Known issues with pull request:
UIAHandler.getUIAUnitFromNVDAUnit()belongs in this pr, in Restore sentence as the default say all reading unit, with a setting to read by paragraph or line #20467 or in a separate one against master. Note that NotImplementedError is a well-established exception raised by TextInfo.move and TextInfo.expand whereas KeyError is a strange outlier.Code Review Checklist: