From 6c911aca2443e47c554bb6217182813ac0dbc8ee Mon Sep 17 00:00:00 2001 From: burmancomp Date: Thu, 21 Sep 2023 10:15:53 +0300 Subject: [PATCH 1/3] fix 3276 --- source/NVDAObjects/IAccessible/winword.py | 6 ------ source/NVDAObjects/UIA/wordDocument.py | 13 +++++++++++++ user_docs/en/changes.t2t | 3 +++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/source/NVDAObjects/IAccessible/winword.py b/source/NVDAObjects/IAccessible/winword.py index bffd4815748..56b82d2c651 100644 --- a/source/NVDAObjects/IAccessible/winword.py +++ b/source/NVDAObjects/IAccessible/winword.py @@ -47,12 +47,6 @@ def _get_ignoreEditorRevisions(self): ignoreFormatting=False def event_caret(self): - curSelectionPos=self.makeTextInfo(textInfos.POSITION_SELECTION) - lastSelectionPos=getattr(self,'_lastSelectionPos',None) - self._lastSelectionPos=curSelectionPos - if lastSelectionPos: - if curSelectionPos._rangeObj.isEqual(lastSelectionPos._rangeObj): - return super(WordDocument,self).event_caret() def _get_role(self): diff --git a/source/NVDAObjects/UIA/wordDocument.py b/source/NVDAObjects/UIA/wordDocument.py index c8cbefb96c7..7486e0a2607 100644 --- a/source/NVDAObjects/UIA/wordDocument.py +++ b/source/NVDAObjects/UIA/wordDocument.py @@ -36,6 +36,9 @@ ) from NVDAObjects import NVDAObject from scriptHandler import script +import api +import config +from config.configFlags import TetherTo """Support for Microsoft Word via UI Automation.""" @@ -544,7 +547,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. + # Update braille also when tethered to review, and review position + # if review follows caret. braille.handler.handleCaretMove(self) + review.handleCaretMove(self) def event_UIA_notification(self, activityId=None, **kwargs): # #10851: in recent Word 365 releases, UIA notification will cause NVDA to announce edit functions @@ -552,6 +558,13 @@ def event_UIA_notification(self, activityId=None, **kwargs): if activityId == "AccSN2": # Delete activity ID return super(WordDocument, self).event_UIA_notification(**kwargs) + # Try to ensure that braille is updated when UIA is not used and + # ctrl-x or ctrl-z is pressed. + if config.conf["braille"]["tetherTo"] != TetherTo.REVIEW.value: + # Using getFocusObject because self does not work always. + braille.handler.handleCaretMove(api.getFocusObject()) + else: + braille.handler.handleReviewMove() # The following overide of the EditableText._caretMoveBySentenceHelper private method # Falls back to the MS Word object model if available. diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index ebe454d24ab..99d46547d74 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -16,6 +16,9 @@ What's New in NVDA == Bug Fixes == - Reporting of object shortcut keys has been improved. (#10807) +- Braille is updated when control+x, control+z or backspace is pressed. +It is also updated when typing text, and braille is tethered to review and +review follows caret. (#3276) - == Changes for Developers == From 823daf641c8a276c32c2a371ce290abfe9c04714 Mon Sep 17 00:00:00 2001 From: burmancomp Date: Tue, 26 Sep 2023 13:23:36 +0300 Subject: [PATCH 2/3] run added code when UIA should not be used, and minor modifications --- source/NVDAObjects/IAccessible/winword.py | 1 + source/NVDAObjects/UIA/wordDocument.py | 21 +++++++++++---------- user_docs/en/changes.t2t | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/NVDAObjects/IAccessible/winword.py b/source/NVDAObjects/IAccessible/winword.py index 56b82d2c651..2df07a4bb33 100644 --- a/source/NVDAObjects/IAccessible/winword.py +++ b/source/NVDAObjects/IAccessible/winword.py @@ -47,6 +47,7 @@ def _get_ignoreEditorRevisions(self): ignoreFormatting=False def event_caret(self): + self._lastSelectionPos = self.makeTextInfo(textInfos.POSITION_SELECTION) super(WordDocument,self).event_caret() def _get_role(self): diff --git a/source/NVDAObjects/UIA/wordDocument.py b/source/NVDAObjects/UIA/wordDocument.py index 7486e0a2607..b03c6d91b59 100644 --- a/source/NVDAObjects/UIA/wordDocument.py +++ b/source/NVDAObjects/UIA/wordDocument.py @@ -37,8 +37,7 @@ from NVDAObjects import NVDAObject from scriptHandler import script import api -import config -from config.configFlags import TetherTo +import eventHandler """Support for Microsoft Word via UI Automation.""" @@ -549,8 +548,8 @@ def event_textChange(self): # As Microsoft Word does not fire caret events when typing text, even though the caret does move. # Update braille also when tethered to review, and review position # if review follows caret. - braille.handler.handleCaretMove(self) - review.handleCaretMove(self) + 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 @@ -559,12 +558,14 @@ def event_UIA_notification(self, activityId=None, **kwargs): return super(WordDocument, self).event_UIA_notification(**kwargs) # Try to ensure that braille is updated when UIA is not used and - # ctrl-x or ctrl-z is pressed. - if config.conf["braille"]["tetherTo"] != TetherTo.REVIEW.value: - # Using getFocusObject because self does not work always. - braille.handler.handleCaretMove(api.getFocusObject()) - else: - braille.handler.handleReviewMove() + # ctrl-v, ctrl-x or ctrl-z is pressed. + # Using getFocusObject because self does not work always. + if ( + not UIAHandler.shouldUseUIAInMSWord(self.appModule) + and not eventHandler.isPendingEvents("caret", api.getFocusObject()) + ): + eventHandler.queueEvent("caret", api.getFocusObject()) + log.debug(f"{self.appModule.appName}: enqueued caret event") # The following overide of the EditableText._caretMoveBySentenceHelper private method # Falls back to the MS Word object model if available. diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index 101ede312aa..3a4c6b79386 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -18,7 +18,7 @@ What's New in NVDA == Bug Fixes == - Reporting of object shortcut keys has been improved. (#10807) - The SAPI4 synthesizer now properly supports volume, rate and pitch changes embedded in speech. (#15271) -- Braille is updated when control+x, control+z or backspace is pressed. +- Braille is updated when control+v, control+x, control+z or backspace is pressed. It is also updated when typing text, and braille is tethered to review and review follows caret. (#3276) - From 02f94ed9cef68f2a185412d58e7e047cb7056a0d Mon Sep 17 00:00:00 2001 From: burmancomp Date: Tue, 26 Sep 2023 21:00:11 +0300 Subject: [PATCH 3/3] minor fix --- source/NVDAObjects/UIA/wordDocument.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/NVDAObjects/UIA/wordDocument.py b/source/NVDAObjects/UIA/wordDocument.py index b03c6d91b59..8dcea9361a1 100644 --- a/source/NVDAObjects/UIA/wordDocument.py +++ b/source/NVDAObjects/UIA/wordDocument.py @@ -548,7 +548,7 @@ def event_textChange(self): # As Microsoft Word does not fire caret events when typing text, even though the caret does move. # Update braille also when tethered to review, and review position # if review follows caret. - if not eventHandler.isPendingEvents("caret, self"): + if not eventHandler.isPendingEvents("caret", self): eventHandler.queueEvent("caret", self) def event_UIA_notification(self, activityId=None, **kwargs):