Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 of UI Automation in Windows Console: fix setEndPoint/compareEndPoints #10057

Merged
merged 12 commits into from
Aug 12, 2019
33 changes: 30 additions & 3 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,42 @@ def expand(self, unit):
else:
return super(consoleUIATextInfo, self).expand(unit)

def _get_isCollapsed(self):
def compareEndPoints(self, other, which):
"""Works around a UIA bug on Windows 10 1803 and later."""
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
# Even when a console textRange's start and end have been moved to the
# same position, the console incorrectly reports the end as being
# past the start.
# Therefore to decide if the textRange is collapsed,
# Check if it has no text.
# Compare to the start (not the end) when collapsed.
selfEndPoint, otherEndPoint = which.split("To")
if selfEndPoint == "end" and not self.hasNoText:
selfEndPoint = "start"
if otherEndPoint == "End" and not other.hasNoText:
otherEndPoint = "Start"
which = f"{selfEndPoint}To{otherEndPoint}"
return super().compareEndPoints(other, which=which)

def setEndPoint(self, other, which):
"""Works around a UIA bug on Windows 10 1803 and later."""
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
# Even when a console textRange's start and end have been moved to the
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
# same position, the console incorrectly reports the end as being
# past the start.
selfEndPoint, otherEndPoint = which.split("To")
# In this case, there is no need to check selfEndPoint
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
# since it is about to be overwritten in the super call.
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
if otherEndPoint == "End" and not other.hasNoText:
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
otherEndPoint = "Start"
which = f"{selfEndPoint}To{otherEndPoint}"
return super().setEndPoint(other, which=which)

def _get_hasNoText(self):
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
return not bool(self._rangeObj.getText(1))

def _get_isCollapsed(self):
"""Works around a UIA bug on Windows 10 1803 and later."""
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
# To decide if the textRange is collapsed,
# Check if it has no text.
return self.hasNoText

def _getCurrentOffsetInThisLine(self, lineInfo):
"""
Given a caret textInfo expanded to line, returns the index into the
Expand Down