From b153f7ee8fae8fb33efdd50653ba32d07413a277 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Sat, 2 Oct 2021 17:50:09 -0400 Subject: [PATCH] Fix movement at end of document for modern UIA providers (#12898) In Microsoft Word, new builds of Windows Console, and Edgium with UIA enabled, "bottom" is not reported when moving past the end of the document in review. These providers return nonzero when moving collapsed textInfos forward past the end, but simply set them to POSITION_LAST (i.e. collapsed at the very end of the document). If a UIA provider reports that a collapsed range has successfully been moved forward (i.e. move returns nonzero), but the new range is collapsed at POSITION_LAST, return 0 and restore the range to its original position. --- source/NVDAObjects/UIA/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py index e9ed3d49e22..29877cf86e4 100644 --- a/source/NVDAObjects/UIA/__init__.py +++ b/source/NVDAObjects/UIA/__init__.py @@ -775,6 +775,19 @@ def move(self,unit,direction,endPoint=None): res=self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_End,UIAUnit,direction) else: res=self._rangeObj.Move(UIAUnit,direction) + # #12808: When attempting to move a collapsed range past the end of the + # document, modern UIA providers will indicate a successful forward + # move and set the range to POSITION_LAST. If a provider does this, + # we must be at the end, so just act as if we can't move forward. + if res and self.isCollapsed: + endInfo = self.obj.makeTextInfo(textInfos.POSITION_LAST) + if self == endInfo: + log.debugWarning( + f"Forward movement of {res} returned but range would be " + "degenerate at end. Assuming end of document." + ) + self._rangeObj = endInfo._rangeObj + res = 0 #Some Implementations of Move and moveEndpointByUnit return a positive number even if the direction is negative if direction<0 and res>0: res=0-res