Skip to content

Commit

Permalink
Fix movement at end of document for modern UIA providers (nvaccess#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 45f807b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,31 @@ def expand(self,unit):
self._rangeObj.ExpandToEnclosingUnit(UIAUnit)

def move(self,unit,direction,endPoint=None):
# #12808: Store the old range in case we need to restore it (see below).
if direction > 0 and self.isCollapsed:
oldRange = self._rangeObj.clone()
else:
oldRange = None
UIAUnit=UIAHandler.NVDAUnitsToUIAUnits[unit]
if endPoint=="start":
res=self._rangeObj.MoveEndpointByUnit(UIAHandler.TextPatternRangeEndpoint_Start,UIAUnit,direction)
elif endPoint=="end":
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 oldRange:
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 = oldRange
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 45f807b

Please sign in to comment.