Skip to content

Commit 8d3e66f

Browse files
authored
Merge 41e637f into b4db7dc
2 parents b4db7dc + 41e637f commit 8d3e66f

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

source/NVDAObjects/UIA/winConsoleUIA.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,44 @@ def expand(self, unit):
153153
else:
154154
return super(consoleUIATextInfo, self).expand(unit)
155155

156-
def _get_isCollapsed(self):
156+
def compareEndPoints(self, other, which):
157157
"""Works around a UIA bug on Windows 10 1803 and later."""
158158
# Even when a console textRange's start and end have been moved to the
159159
# same position, the console incorrectly reports the end as being
160160
# past the start.
161-
# Therefore to decide if the textRange is collapsed,
162-
# Check if it has no text.
161+
# Compare to the start (not the end) when collapsed.
162+
selfEndPoint, otherEndPoint = which.split("To")
163+
if selfEndPoint == "end" and not self._isCollapsed:
164+
selfEndPoint = "start"
165+
if otherEndPoint == "End" and not other._isCollapsed:
166+
otherEndPoint = "Start"
167+
which = f"{selfEndPoint}To{otherEndPoint}"
168+
return super().compareEndPoints(other, which=which)
169+
170+
def setEndPoint(self, other, which):
171+
"""Override of L{textInfos.TextInfo.setEndPoint}.
172+
Works around a UIA bug on Windows 10 1803 and later that means we can not trust
173+
the "end" endpoint of a collapsed (empty) text range for comparisons.
174+
"""
175+
selfEndPoint, otherEndPoint = which.split("To")
176+
# In this case, there is no need to check if self is collapsed
177+
# since the point of this method is to change its text range, modifying the "end" endpoint of a collapsed
178+
# text range is fine.
179+
if otherEndPoint == "End" and not other._isCollapsed:
180+
otherEndPoint = "Start"
181+
which = f"{selfEndPoint}To{otherEndPoint}"
182+
return super().setEndPoint(other, which=which)
183+
184+
def _get__isCollapsed(self):
185+
"""Works around a UIA bug on Windows 10 1803 and later that means we can not trust the "end" endpoint of a collapsed (empty) text range for comparisons.
186+
Instead we check to see if we can get the first character from the text range. A collapsed range will not have any characters and will return an empty string."""
163187
return not bool(self._rangeObj.getText(1))
164188

189+
def _get_isCollapsed(self):
190+
# To decide if the textRange is collapsed,
191+
# Check if it has no text.
192+
return self._isCollapsed
193+
165194
def _getCurrentOffsetInThisLine(self, lineInfo):
166195
"""
167196
Given a caret textInfo expanded to line, returns the index into the

0 commit comments

Comments
 (0)