Skip to content

Commit

Permalink
Incubates #7997
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelDCurran committed Feb 14, 2018
2 parents 298575a + 76b5179 commit 32384f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/NVDAObjects/UIA/__init__.py
Expand Up @@ -268,7 +268,12 @@ def _getFormatFieldAtRange(self,textRange,formatConfig,ignoreMixedValues=False):
def __init__(self,obj,position,_rangeObj=None):
super(UIATextInfo,self).__init__(obj,position)
if _rangeObj:
self._rangeObj=_rangeObj.clone()
try:
self._rangeObj=_rangeObj.clone()
except COMError:
# IUIAutomationTextRange::clone can sometimes fail, such as in UWP account login screens
log.debugWarning("Could not clone range",exc_info=True)
raise RuntimeError("Could not clone range")
elif position in (textInfos.POSITION_CARET,textInfos.POSITION_SELECTION):
try:
sel=self.obj.UIATextPattern.GetSelection()
Expand Down
13 changes: 13 additions & 0 deletions source/NVDAObjects/UIA/edge.py
Expand Up @@ -572,6 +572,19 @@ def shouldPassThrough(self,obj,reason=None):
return True
return super(EdgeHTMLTreeInterceptor,self).shouldPassThrough(obj,reason=reason)

def makeTextInfo(self,position):
try:
return super(EdgeHTMLTreeInterceptor,self).makeTextInfo(position)
except RuntimeError as e:
# sometimes the stored TextRange we have for the caret/selection can die if the page mutates too much.
# Therefore, if we detect this, just give back the first position in the document, updating our stored version as we go.
if position in (textInfos.POSITION_SELECTION,textInfos.POSITION_CARET):
log.debugWarning("%s died. Using first position instead."%position)
info=self.makeTextInfo(textInfos.POSITION_FIRST)
self._selection=info
return info
raise e

class EdgeHTMLRoot(EdgeNode):

treeInterceptorClass=EdgeHTMLTreeInterceptor
Expand Down
3 changes: 3 additions & 0 deletions source/UIABrowseMode.py
Expand Up @@ -336,6 +336,9 @@ def _get_UIAElementAtStart(self):
class UIABrowseModeDocument(UIADocumentWithTableNavigation,browseMode.BrowseModeDocumentTreeInterceptor):

TextInfo=UIABrowseModeDocumentTextInfo
# UIA browseMode documents cannot remember caret positions across loads (I.e. when going back a page in Edge)
# Because UIA TextRanges are opaque and are tied specifically to one particular document.
shouldRememberCaretPositionAcrossLoads=False

def _iterNodesByType(self,nodeType,direction="next",pos=None):
if nodeType.startswith("heading"):
Expand Down

0 comments on commit 32384f9

Please sign in to comment.