Skip to content

Commit

Permalink
Merge 40b6e8a into a380b6a
Browse files Browse the repository at this point in the history
  • Loading branch information
burmancomp authored Oct 6, 2023
2 parents a380b6a + 40b6e8a commit c981565
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
36 changes: 35 additions & 1 deletion source/NVDAObjects/IAccessible/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@
import textInfos
import eventHandler
import scriptHandler
from scriptHandler import script
import ui
from . import IAccessible
from displayModel import EditableTextDisplayModelTextInfo
from ..behaviors import EditableTextWithoutAutoSelectDetection
import NVDAObjects.window.winword as winWordWindowModule
from speech import sayAll
import inputCore


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

treeInterceptorClass = winWordWindowModule.WordDocumentTreeInterceptor
shouldCreateTreeInterceptor=False
TextInfo = winWordWindowModule.WordDocumentTextInfo
# Should braille and review position be updated, set to True in
# L{script_updateBrailleAndReviewPosition}.
_fromUpdateBrailleAndReviewPosition = False

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

def event_caret(self):
def event_caret(self) -> None:
curSelectionPos=self.makeTextInfo(textInfos.POSITION_SELECTION)
lastSelectionPos=getattr(self,'_lastSelectionPos',None)
self._lastSelectionPos=curSelectionPos
if lastSelectionPos:
if curSelectionPos._rangeObj.isEqual(lastSelectionPos._rangeObj):
if self._fromUpdateBrailleAndReviewPosition:
super().event_caret()
self._fromUpdateBrailleAndReviewPosition = False
return
super(WordDocument,self).event_caret()

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

@script(
gestures=(
"kb:control+v", "kb:control+x", "kb:control+y", "kb:control+z",
"kb:alt+backspace", "kb:backspace", "kb:control+backspace"
)
)
def script_updateBrailleAndReviewPosition(self, gesture: inputCore.InputGesture) -> None:
"""Helper script to update braille and review position.
Caret event is not always fired when control+v, control+x, control+y
or control+z (alt+backspace) is pressed so enqueuing caret event for that.
When backspace or control+backspace is pressed and hold down, braille
may not always be updated. Allowing braille and review position updates
in L{event_caret} seems to fix that problem.
"""
# Ensuring braille and review position updates are allowed in caret event.
self._fromUpdateBrailleAndReviewPosition = True
# Speech output when backspace or control+backspace is pressed.
if gesture._get_displayName() == "backspace":
self.script_caret_backspaceCharacter(gesture)
elif gesture._get_displayName() == "ctrl+backspace":
self.script_caret_backspaceWord(gesture)
else:
gesture.send()
if not eventHandler.isPendingEvents("caret", self):
eventHandler.queueEvent("caret", self)

def focusOnActiveDocument(self, officeChartObject):
rangeStart=officeChartObject.Parent.Range.Start
self.WinwordApplicationObject.ActiveDocument.Range(rangeStart, rangeStart).Select()
Expand Down
6 changes: 5 additions & 1 deletion source/NVDAObjects/UIA/wordDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from NVDAObjects import NVDAObject
from scriptHandler import script
import eventHandler


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

def event_UIA_notification(self, activityId=None, **kwargs):
# #10851: in recent Word 365 releases, UIA notification will cause NVDA to announce edit functions
Expand Down
3 changes: 3 additions & 0 deletions user_docs/en/changes.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ This option now announces additional relevant information about an object when t
- The SAPI4 synthesizer now properly supports volume, rate and pitch changes embedded in speech. (#15271)
- Multi line state is now correctly reported in applications using Java Access Bridge. (#14609)
- 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)
- Braille is updated when control+v, control+x, control+z or backspace is
pressed in MS Word when uia is not used. It is also updated when typing text,
and braille is tethered to review and review follows caret. (#3276)
-

== Changes for Developers ==
Expand Down

0 comments on commit c981565

Please sign in to comment.