2323from ..behaviors import EditableTextWithoutAutoSelectDetection
2424import NVDAObjects .window .winword as winWordWindowModule
2525from speech import sayAll
26+ import api
27+ import inputCore
28+ from typing import Callable
2629
2730
2831class WordDocument (IAccessible , EditableTextWithoutAutoSelectDetection , winWordWindowModule .WordDocument ):
@@ -47,12 +50,7 @@ def _get_ignoreEditorRevisions(self):
4750 ignoreFormatting = False
4851
4952 def event_caret (self ):
50- curSelectionPos = self .makeTextInfo (textInfos .POSITION_SELECTION )
51- lastSelectionPos = getattr (self ,'_lastSelectionPos' ,None )
52- self ._lastSelectionPos = curSelectionPos
53- if lastSelectionPos :
54- if curSelectionPos ._rangeObj .isEqual (lastSelectionPos ._rangeObj ):
55- return
53+ self ._lastSelectionPos = self .makeTextInfo (textInfos .POSITION_SELECTION )
5654 super (WordDocument ,self ).event_caret ()
5755
5856 def _get_role (self ):
@@ -369,6 +367,21 @@ def script_previousParagraph(self,gesture):
369367 self ._caretScriptPostMovedHelper (textInfos .UNIT_PARAGRAPH ,gesture ,None )
370368 script_previousParagraph .resumeSayAllMode = sayAll .CURSOR .CARET
371369
370+ def script_paste (self , gesture : inputCore .InputGesture ) -> None :
371+ """Helper script to update braille and review position."""
372+ gesture .send ()
373+ self ._updateBraille ()
374+
375+ def _updateBraille (self ) -> None :
376+ """Update braille and review position when helper scripts like script_paste are executed."""
377+ # Using getFocusObject because self does not work always.
378+ if not eventHandler .isPendingEvents ("caret" , api .getFocusObject ()):
379+ eventHandler .queueEvent ("caret" , api .getFocusObject ())
380+ log .debug (f"{ self .appModule .appName } : enqueued caret event" )
381+
382+ script_cut : Callable [[inputCore .InputGesture ], None ] = script_paste
383+ script_undo : Callable [[inputCore .InputGesture ], None ] = script_paste
384+
372385 def focusOnActiveDocument (self , officeChartObject ):
373386 rangeStart = officeChartObject .Parent .Range .Start
374387 self .WinwordApplicationObject .ActiveDocument .Range (rangeStart , rangeStart ).Select ()
@@ -390,6 +403,9 @@ def focusOnActiveDocument(self, officeChartObject):
390403 "kb:alt+pageUp" :"caret_moveByCell" ,
391404 "kb:alt+pageDown" :"caret_moveByCell" ,
392405 "kb:NVDA+alt+c" :"reportCurrentComment" ,
406+ "kb:control+v" : "paste" ,
407+ "kb:control+x" : "cut" ,
408+ "kb:control+z" : "undo" ,
393409 }
394410
395411
0 commit comments