Skip to content

Commit b7e31d0

Browse files
authored
Merge 9ba60ae into a9bcdff
2 parents a9bcdff + 9ba60ae commit b7e31d0

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

source/NVDAObjects/UIA/__init__.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -729,15 +729,15 @@ def _getTextWithFieldsForUIARange( # noqa: C901
729729
) -> Generator[textInfos.TextInfo.TextOrFieldsT, None, None]:
730730
"""
731731
Yields start and end control fields, and text, for the given UI Automation text range.
732-
@param rootElement: the highest ancestor that encloses the given text range. This function will not walk higher than this point.
733-
@param textRange: the UI Automation text range whos content should be fetched.
734-
@param formatConfig: the types of formatting requested.
735-
@type formatConfig: a dictionary of NVDA document formatting configuration keys
732+
:param rootElement: the highest ancestor that encloses the given text range. This function will not walk higher than this point.
733+
:param textRange: the UI Automation text range whos content should be fetched.
734+
:param formatConfig: the types of formatting requested.
735+
:type formatConfig: a dictionary of NVDA document formatting configuration keys
736736
with values set to true for those types that should be fetched.
737-
@param includeRoot: If true, then a control start and end will be yielded for the root element.
738-
@param alwaysWalkAncestors: If true then control fields will be yielded for any element enclosing the given text range, that is a descendant of the root element. If false then the root element may be assumed to be the only ancestor.
739-
@param recurseChildren: If true, this function will be recursively called for each child of the given text range, clipped to the bounds of this text range. Formatted text between the children will also be yielded. If false, only formatted text will be yielded.
740-
@param _rootElementClipped: Indicates if textRange represents all of the given rootElement,
737+
:param includeRoot: If true, then a control start and end will be yielded for the root element.
738+
:param alwaysWalkAncestors: If true then control fields will be yielded for any element enclosing the given text range, that is a descendant of the root element. If false then the root element may be assumed to be the only ancestor.
739+
:param recurseChildren: If true, this function will be recursively called for each child of the given text range, clipped to the bounds of this text range. Formatted text between the children will also be yielded. If false, only formatted text will be yielded.
740+
:param _rootElementClipped: Indicates if textRange represents all of the given rootElement,
741741
or is clipped at the start or end.
742742
"""
743743
debug = UIAHandler._isDebug() and log.isEnabledFor(log.DEBUG)
@@ -777,7 +777,7 @@ def _getTextWithFieldsForUIARange( # noqa: C901
777777
break
778778
else:
779779
if debug:
780-
log.debug("parentElement: %s" % parentElement.currentLocalizedControlType)
780+
log.debug(f"parentElement: {parentElement.currentLocalizedControlType!r}")
781781
try:
782782
parentRange = self.obj.UIATextPattern.rangeFromChild(parentElement)
783783
except COMError:
@@ -786,22 +786,26 @@ def _getTextWithFieldsForUIARange( # noqa: C901
786786
if debug:
787787
log.debug("parentRange is NULL. Breaking")
788788
break
789-
clippedStart = (
790-
textRange.CompareEndpoints(
791-
UIAHandler.TextPatternRangeEndpoint_Start,
792-
parentRange,
793-
UIAHandler.TextPatternRangeEndpoint_Start,
794-
)
795-
> 0
789+
startCmp = textRange.CompareEndpoints(
790+
UIAHandler.TextPatternRangeEndpoint_Start,
791+
parentRange,
792+
UIAHandler.TextPatternRangeEndpoint_Start,
796793
)
797-
clippedEnd = (
798-
textRange.CompareEndpoints(
799-
UIAHandler.TextPatternRangeEndpoint_End,
800-
parentRange,
801-
UIAHandler.TextPatternRangeEndpoint_End,
802-
)
803-
< 0
794+
endCmp = textRange.CompareEndpoints(
795+
UIAHandler.TextPatternRangeEndpoint_End,
796+
parentRange,
797+
UIAHandler.TextPatternRangeEndpoint_End,
804798
)
799+
clippedStart = startCmp > 0
800+
if endCmp == startCmp and endCmp > 0:
801+
if debug:
802+
log.debug(
803+
f"The end of the inner range is greater than the end of the outer range ({endCmp}). "
804+
"This is likely a bug in the UIA implementation. Assuming clippedEnd=True",
805+
)
806+
clippedEnd = True
807+
else:
808+
clippedEnd = endCmp < 0
805809
parentElements.append((parentElement, (clippedStart, clippedEnd)))
806810
parentElement = UIAHandler.handler.baseTreeWalker.getParentElementBuildCache(
807811
parentElement,

user_docs/en/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
* In WinUI 3 apps including Microsoft Copilot and parts of Windows 11 File Explorer, NVDA will no longer fail to announce controls when using mouse and touch interaction. (#17407, #17771, @josephsl)
1414
* Fixed some rare cases where NVDA playing sounds could result in unexpected errors. (#17918, @LeonarddeR)
15+
* In Microsoft Word, when UIA is enabled, NVDA will no longer braille redundant table end markers when the cursor is in a table cell. (#15828, @LeonarddeR)
1516

1617
### Changes for Developers
1718

0 commit comments

Comments
 (0)