Skip to content

Commit e58e650

Browse files
Merge 235a706 into 22dd011
2 parents 22dd011 + 235a706 commit e58e650

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

source/NVDAObjects/UIA/wordDocument.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55

66
from comtypes import COMError
77
from collections import defaultdict
8+
from scriptHandler import isScriptWaiting
89
import textInfos
910
import eventHandler
1011
import UIAHandler
1112
from logHandler import log
1213
import controlTypes
1314
import ui
1415
import speech
16+
import review
17+
import braille
1518
import api
1619
import browseMode
1720
from UIABrowseMode import UIABrowseModeDocument, UIADocumentWithTableNavigation, UIATextAttributeQuicknavIterator, TextAttribUIATextInfoQuickNavItem
1821
from UIAUtils import *
1922
from . import UIA, UIATextInfo
20-
from NVDAObjects.window.winword import WordDocument as WordDocumentBase
23+
from NVDAObjects.window.winword import (
24+
WordDocument as WordDocumentBase,
25+
WordDocumentTextInfo as LegacyWordDocumentTextInfo
26+
)
2127
from scriptHandler import script
2228

2329

@@ -413,6 +419,43 @@ def event_UIA_notification(self, activityId=None, **kwargs):
413419
return
414420
super(WordDocument, self).event_UIA_notification(**kwargs)
415421

422+
# The following overide of the EditableText._caretMoveBySentenceHelper private method
423+
# Falls back to the MS Word object model if available.
424+
# This override should be removed as soon as UI Automation in MS Word has the ability to move by sentence.
425+
def _caretMoveBySentenceHelper(self, gesture, direction):
426+
if isScriptWaiting():
427+
return
428+
if not self.WinwordSelectionObject:
429+
# Legacy object model not available.
430+
gesture.send()
431+
return
432+
# Using the legacy object model,
433+
# Move the caret to the next sentence in the requested direction.
434+
legacyInfo = LegacyWordDocumentTextInfo(self,textInfos.POSITION_CARET)
435+
legacyInfo.move(textInfos.UNIT_SENTENCE, direction)
436+
legacyInfo.updateCaret()
437+
# Fetch the new caret position (start of the next sentence) with UI Automation.
438+
startInfo = self.makeTextInfo(textInfos.POSITION_CARET)
439+
# With the legacy object model,
440+
# Move the caret to the end of the new sentence.
441+
legacyInfo.move(textInfos.UNIT_SENTENCE, 1)
442+
legacyInfo.updateCaret()
443+
# Fetch the new caret position (end of the next sentence) with UI automation.
444+
endInfo = self.makeTextInfo(textInfos.POSITION_CARET)
445+
# Make a UI automation text range spanning the entire next sentence.
446+
info = startInfo.copy()
447+
info.end = endInfo.end
448+
# Move the caret back to the start of the next sentence,
449+
# where it should be left for the user.
450+
startInfo.updateCaret()
451+
# Speak the sentence moved to
452+
speech.speakTextInfo(info, unit=textInfos.UNIT_SENTENCE, reason=controlTypes.OutputReason.CARET)
453+
# Forget the word currently being typed as the user has moved the caret somewhere else.
454+
speech.clearTypedWordBuffer()
455+
# Alert review and braille the caret has moved to its new position
456+
review.handleCaretMove(info)
457+
braille.handler.handleCaretMove(self)
458+
416459
@script(
417460
gesture="kb:NVDA+alt+c",
418461
# Translators: a description for a script that reports the comment at the caret.

0 commit comments

Comments
 (0)