|
5 | 5 |
|
6 | 6 | from comtypes import COMError |
7 | 7 | from collections import defaultdict |
| 8 | +from scriptHandler import isScriptWaiting |
8 | 9 | import textInfos |
9 | 10 | import eventHandler |
10 | 11 | import UIAHandler |
11 | 12 | from logHandler import log |
12 | 13 | import controlTypes |
13 | 14 | import ui |
14 | 15 | import speech |
| 16 | +import review |
| 17 | +import braille |
15 | 18 | import api |
16 | 19 | import browseMode |
17 | 20 | from UIABrowseMode import UIABrowseModeDocument, UIADocumentWithTableNavigation, UIATextAttributeQuicknavIterator, TextAttribUIATextInfoQuickNavItem |
18 | 21 | from UIAUtils import * |
19 | 22 | 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 | +) |
21 | 27 | from scriptHandler import script |
22 | 28 |
|
23 | 29 |
|
@@ -413,6 +419,43 @@ def event_UIA_notification(self, activityId=None, **kwargs): |
413 | 419 | return |
414 | 420 | super(WordDocument, self).event_UIA_notification(**kwargs) |
415 | 421 |
|
| 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 | + |
416 | 459 | @script( |
417 | 460 | gesture="kb:NVDA+alt+c", |
418 | 461 | # Translators: a description for a script that reports the comment at the caret. |
|
0 commit comments