Skip to content

Commit

Permalink
Ignore RuntimeError when moving in word. (PR #7133)
Browse files Browse the repository at this point in the history
Pressing end while in browse mode of an empty Microsoft Word document no longer causes a runtime error.

Fix for #7009
  • Loading branch information
feerrenrut committed May 30, 2017
1 parent 6ca7499 commit 1c068b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,11 @@ def collapse(self,end=False):
if end:
oldEndOffset=self._rangeObj.end
self._rangeObj.collapse(wdCollapseEnd if end else wdCollapseStart)
if end and self._rangeObj.end<oldEndOffset:
newEndOffset = self._rangeObj.end
# the new endOffset should not have become smaller than the old endOffset, this could cause an infinite loop in
# a case where you called move end then collapse until the size of the range is no longer being reduced.
# For an example of this see sayAll (specifically readTextHelper_generator in sayAllHandler.py)
if end and newEndOffset < oldEndOffset :
raise RuntimeError

def copy(self):
Expand Down
9 changes: 8 additions & 1 deletion source/cursorManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ def _caretMovementScriptHelper(self,gesture,unit,direction=None,posConstant=text
if not self._lastSelectionMovedStart and not oldInfo.isCollapsed:
info.move(textInfos.UNIT_CHARACTER,-1)
if posUnit is not None:
# expand and collapse to ensure that we are aligned with the end of the intended unit
info.expand(posUnit)
info.collapse(end=posUnitEnd)
try:
info.collapse(end=posUnitEnd)
except RuntimeError:
# MS Word has a "virtual linefeed" at the end of the document which can cause RuntimeError to be raised.
# In this case it can be ignored.
# See #7009
pass
if posUnitEnd:
info.move(textInfos.UNIT_CHARACTER,-1)
if direction is not None:
Expand Down
1 change: 1 addition & 0 deletions source/sayAllHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def readTextHelper_generator(cursor):
try:
reader.collapse(end=True)
except RuntimeError: #MS Word when range covers end of document
# Word specific: without this exception to indicate that further collapsing is not posible, say-all could enter an infinite loop.
speech.speakWithoutPauses(None)
keepReading=False
else:
Expand Down

0 comments on commit 1c068b7

Please sign in to comment.