Skip to content

Commit

Permalink
Fix movement at end of document for modern UIA providers (#12898)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
codeofdusk committed Oct 2, 2021
1 parent df92ef6 commit b153f7e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b153f7e

Please sign in to comment.