Fix UIA text unit crash and Word sentence-nav boundary wraparound (#20498)
Follow-up to #19367.
based on beta because 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() for UNIT_SENTENCE (related to #20467), two issues surfaced:
UIATextInfo.expand()/move() raise an uncaught KeyError for any NVDA text unit UIA has no mapping for, instead of a NotImplementedError, which is the contract TextInfo.expand()/move() callers rely on for a graceful no-op. UNIT_SENTENCE is one such unmapped unit, so calling expand()/move() with it on a UIA TextInfo crashed instead of raising cleanly.
Word's native MoveBySentence/ExpandToEnclosingSentence UIA 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:
Moving by sentence in Word (alt+downArrow/alt+upArrow) at the start/end of a document now stops there instead of wrapping around to the opposite end.
No new user-facing feature: this is a fix to code introduced in UI Automation in Microsoft Word: Use move by sentence custom pattern when available instead of the legacy model #19367, which itself has no changes.md entry as it was an internal backend swap.
Description of developer facing changes:
Added UIAHandler.getUIAUnitFromNVDAUnit(), which raises NotImplementedError instead of letting a KeyError escape NVDAUnitsToUIAUnits lookups. UIATextInfo.expand()/move() now use it. This is a general robustness fix for the UIA TextInfo API, 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 into msWord_textRange_moveBySentence(), msWord_textRange_moveEndpointBySentence(), and msWord_textRange_expandToEnclosingSentence().
As msWord_moveTextRangeBySentence is 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:
Wired native Word sentence support directly into WordDocumentTextInfo.expand()/move() for UNIT_SENTENCE. The sentence-navigation script now goes through this TextInfo API instead of calling the remote op directly.
Added a boundary guard in 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.