Skip to content

Commit c981565

Browse files
authored
Merge 40b6e8a into a380b6a
2 parents a380b6a + 40b6e8a commit c981565

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

source/NVDAObjects/IAccessible/winword.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,24 @@
1717
import textInfos
1818
import eventHandler
1919
import scriptHandler
20+
from scriptHandler import script
2021
import ui
2122
from . import IAccessible
2223
from displayModel import EditableTextDisplayModelTextInfo
2324
from ..behaviors import EditableTextWithoutAutoSelectDetection
2425
import NVDAObjects.window.winword as winWordWindowModule
2526
from speech import sayAll
27+
import inputCore
2628

2729

2830
class WordDocument(IAccessible, EditableTextWithoutAutoSelectDetection, winWordWindowModule.WordDocument):
2931

3032
treeInterceptorClass = winWordWindowModule.WordDocumentTreeInterceptor
3133
shouldCreateTreeInterceptor=False
3234
TextInfo = winWordWindowModule.WordDocumentTextInfo
35+
# Should braille and review position be updated, set to True in
36+
# L{script_updateBrailleAndReviewPosition}.
37+
_fromUpdateBrailleAndReviewPosition = False
3338

3439
def _get_ignoreEditorRevisions(self):
3540
try:
@@ -46,12 +51,15 @@ def _get_ignoreEditorRevisions(self):
4651
#: True if formatting should be ignored (text only) such as for spellCheck error field
4752
ignoreFormatting=False
4853

49-
def event_caret(self):
54+
def event_caret(self) -> None:
5055
curSelectionPos=self.makeTextInfo(textInfos.POSITION_SELECTION)
5156
lastSelectionPos=getattr(self,'_lastSelectionPos',None)
5257
self._lastSelectionPos=curSelectionPos
5358
if lastSelectionPos:
5459
if curSelectionPos._rangeObj.isEqual(lastSelectionPos._rangeObj):
60+
if self._fromUpdateBrailleAndReviewPosition:
61+
super().event_caret()
62+
self._fromUpdateBrailleAndReviewPosition = False
5563
return
5664
super(WordDocument,self).event_caret()
5765

@@ -369,6 +377,32 @@ def script_previousParagraph(self,gesture):
369377
self._caretScriptPostMovedHelper(textInfos.UNIT_PARAGRAPH,gesture,None)
370378
script_previousParagraph.resumeSayAllMode = sayAll.CURSOR.CARET
371379

380+
@script(
381+
gestures=(
382+
"kb:control+v", "kb:control+x", "kb:control+y", "kb:control+z",
383+
"kb:alt+backspace", "kb:backspace", "kb:control+backspace"
384+
)
385+
)
386+
def script_updateBrailleAndReviewPosition(self, gesture: inputCore.InputGesture) -> None:
387+
"""Helper script to update braille and review position.
388+
Caret event is not always fired when control+v, control+x, control+y
389+
or control+z (alt+backspace) is pressed so enqueuing caret event for that.
390+
When backspace or control+backspace is pressed and hold down, braille
391+
may not always be updated. Allowing braille and review position updates
392+
in L{event_caret} seems to fix that problem.
393+
"""
394+
# Ensuring braille and review position updates are allowed in caret event.
395+
self._fromUpdateBrailleAndReviewPosition = True
396+
# Speech output when backspace or control+backspace is pressed.
397+
if gesture._get_displayName() == "backspace":
398+
self.script_caret_backspaceCharacter(gesture)
399+
elif gesture._get_displayName() == "ctrl+backspace":
400+
self.script_caret_backspaceWord(gesture)
401+
else:
402+
gesture.send()
403+
if not eventHandler.isPendingEvents("caret", self):
404+
eventHandler.queueEvent("caret", self)
405+
372406
def focusOnActiveDocument(self, officeChartObject):
373407
rangeStart=officeChartObject.Parent.Range.Start
374408
self.WinwordApplicationObject.ActiveDocument.Range(rangeStart, rangeStart).Select()

source/NVDAObjects/UIA/wordDocument.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
)
3737
from NVDAObjects import NVDAObject
3838
from scriptHandler import script
39+
import eventHandler
3940

4041

4142
"""Support for Microsoft Word via UI Automation."""
@@ -544,7 +545,10 @@ class WordDocument(UIADocumentWithTableNavigation,WordDocumentNode,WordDocumentB
544545
def event_textChange(self):
545546
# Ensure Braille is updated when text changes,
546547
# As Microsoft Word does not fire caret events when typing text, even though the caret does move.
547-
braille.handler.handleCaretMove(self)
548+
# Update braille also when tethered to review, and review position
549+
# if review follows caret.
550+
if not eventHandler.isPendingEvents("caret", self):
551+
eventHandler.queueEvent("caret", self)
548552

549553
def event_UIA_notification(self, activityId=None, **kwargs):
550554
# #10851: in recent Word 365 releases, UIA notification will cause NVDA to announce edit functions

user_docs/en/changes.t2t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ This option now announces additional relevant information about an object when t
2626
- The SAPI4 synthesizer now properly supports volume, rate and pitch changes embedded in speech. (#15271)
2727
- Multi line state is now correctly reported in applications using Java Access Bridge. (#14609)
2828
- In LibreOffice, words deleted using the ``control+backspace`` keyboard shortcut are now also properly announced when the deleted word is followed by whitespace (like spaces and tabs). (#15436)
29+
- Braille is updated when control+v, control+x, control+z or backspace is
30+
pressed in MS Word when uia is not used. It is also updated when typing text,
31+
and braille is tethered to review and review follows caret. (#3276)
2932
-
3033

3134
== Changes for Developers ==

0 commit comments

Comments
 (0)