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

MozillaCompoundTextInfo: Don't adjust for the end of a line if the previous character is a line feed. #16763

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions source/NVDAObjects/IAccessible/ia2TextMozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ def _getControlFieldForObject(self, obj, ignoreEditableText=True):
controlField["uniqueID"] = uniqueID
return controlField

def _isCaretAtEndOfLine(self, caretObj: IAccessible) -> bool:
# #3156: Even though the insertion point at the end of a line might have
# the same offset as the start of the next, some implementations
# support IA2_TEXT_OFFSET_CARET to take this into account. Use this to
# determine whether we are at this position.
try:
start, end, text = caretObj.IAccessibleTextObject.textAtOffset(
IA2.IA2_TEXT_OFFSET_CARET, IA2.IA2_TEXT_BOUNDARY_CHAR
)
# If the offsets are different, this means there is a character, which
# means this is not the insertion point at the end of a line.
if start != end:
return False
# If there is a line feed before us, this is an empty line. We don't want
# to do any special adjustment in this case. Otherwise, we will report the
# previous line instead of the empty one.
if start > 0 and caretObj.IAccessibleTextObject.text(start - 1, start) == "\n":
return False
return True
except COMError:
log.debugWarning(
"Couldn't determine if caret is at end of line insertion point",
exc_info=True
)
return False

def __init__(self, obj, position):
super(MozillaCompoundTextInfo, self).__init__(obj, position)
# #3156: The position when the caret is at the end of a wrapped line (e.g.
Expand Down Expand Up @@ -128,24 +154,7 @@ def __init__(self, obj, position):
caretTi, caretObj = self._findContentDescendant(obj, textInfos.POSITION_CARET)
except LookupError:
raise RuntimeError("No caret")
# #3156: Even though the insertion point at the end of a line might have
# the same offset as the start of the next, some implementations
# support IA2_TEXT_OFFSET_CARET to take this into account. Use this to
# determine whether we are at this position.
try:
start, end, text = caretObj.IAccessibleTextObject.textAtOffset(
IA2.IA2_TEXT_OFFSET_CARET, IA2.IA2_TEXT_BOUNDARY_CHAR
)
# If the offsets are the same, this means no character, which means this is
# the insertion point at the end of a line.
self._isEndOfLineInsertionPoint = start == end
except COMError:
# We already set self._isEndOfLineInsertionPoint to False above and that's
# what we should assume on failure.
log.debugWarning(
"Couldn't determine if caret is at end of line insertion point",
exc_info=True
)
self._isEndOfLineInsertionPoint = self._isCaretAtEndOfLine(caretObj)
seanbudd marked this conversation as resolved.
Show resolved Hide resolved
if caretObj is not obj and caretObj.IA2Attributes.get("display") == "inline" and caretTi.compareEndPoints(self._makeRawTextInfo(caretObj, textInfos.POSITION_ALL), "startToEnd") == 0:
# The caret is at the end of an inline object.
# This will report "blank", but we want to report the character just after the caret.
Expand Down