Skip to content
Merged
Changes from 1 commit
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
27 changes: 12 additions & 15 deletions source/_magnifier/utils/focusManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import mouseHandler
import time
import locationHelper
import textInfos
from textInfos.offsets import OffsetsTextInfo
from .types import Coordinates, FocusType


Expand Down Expand Up @@ -174,7 +176,7 @@ def _getReviewPosition(self) -> Coordinates | None:
pass
return None

def _getPointAtStart(self, textInfo) -> locationHelper.Point:
def _getPointAtStart(self, textInfo: textInfos.TextInfo) -> locationHelper.Point:
"""
Get a point for the start of a text range with a local end-of-text fallback.

Expand All @@ -184,28 +186,23 @@ def _getPointAtStart(self, textInfo) -> locationHelper.Point:
"""
try:
return textInfo.pointAtStart
except (NotImplementedError, LookupError, AttributeError):
pass
except (NotImplementedError, LookupError, AttributeError) as e:
Comment thread
seanbudd marked this conversation as resolved.
originalExc = e

# Only apply the fallback for TextInfos exposing the offset-based internals
# we need. Otherwise, preserve the original failure.
if not (
getattr(textInfo, "isCollapsed", False)
and getattr(textInfo, "_startOffset", 0) > 0
and hasattr(textInfo, "_getBoundingRectFromOffset")
):
raise LookupError
if not (isinstance(textInfo, OffsetsTextInfo) and textInfo.isCollapsed and textInfo._startOffset > 0):
raise originalExc
Comment thread
seanbudd marked this conversation as resolved.

prevOffset = textInfo._startOffset - 1
try:
return textInfo._getBoundingRectFromOffset(prevOffset).topRight
except (NotImplementedError, LookupError, AttributeError):
if hasattr(textInfo, "_getPointFromOffset"):
try:
return textInfo._getPointFromOffset(prevOffset)
except (NotImplementedError, LookupError, AttributeError):
pass
raise LookupError
try:
return textInfo._getPointFromOffset(prevOffset)
except (NotImplementedError, LookupError, AttributeError):
pass
raise originalExc
Comment thread
seanbudd marked this conversation as resolved.

def _getNavigatorObjectLocation(self) -> Coordinates | None:
"""
Expand Down
Loading