From c5e47e4de33bcb95be345a0765dabf0012ad5ef7 Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:35:38 +1000 Subject: [PATCH 1/8] Added implementation of _setCaretOffset to TextFrameTextInfo --- source/appModules/powerpnt.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/appModules/powerpnt.py b/source/appModules/powerpnt.py index f0e9b88ee8e..246b1218693 100644 --- a/source/appModules/powerpnt.py +++ b/source/appModules/powerpnt.py @@ -1128,6 +1128,14 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True) formatField["link"] = True return formatField, (startOffset, endOffset) + def _setCaretOffset(self, offset: int): + if not 0 <= offset <= (maxLength := self.storyLength): + log.debugWarning(f"Got out of range {offset=} (min 0, max {maxLength}. Clamping.", stack_inf=True) + offset = max(0, min(offset, maxLength)) + # Use the TextRange.select method to move the text caret to a 0-length TextRange. + # The TextRange.characters method is 1-indexed. + self.obj.ppObject.textRange.characters(offset + 1, 0).select() + class Table(Shape): """Represents the table shape in Powerpoint. Provides row and column counts.""" From 11ef15b59791f94ea9f0acfd2cba1038d7bbc2e1 Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:17:19 +1000 Subject: [PATCH 2/8] Fixed an error where I thought storyLength was a auto property --- source/appModules/powerpnt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/appModules/powerpnt.py b/source/appModules/powerpnt.py index 246b1218693..d4160f50611 100644 --- a/source/appModules/powerpnt.py +++ b/source/appModules/powerpnt.py @@ -1129,7 +1129,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True) return formatField, (startOffset, endOffset) def _setCaretOffset(self, offset: int): - if not 0 <= offset <= (maxLength := self.storyLength): + if not 0 <= offset <= (maxLength := self._getStoryLength()): log.debugWarning(f"Got out of range {offset=} (min 0, max {maxLength}. Clamping.", stack_inf=True) offset = max(0, min(offset, maxLength)) # Use the TextRange.select method to move the text caret to a 0-length TextRange. From 656c436ad1a933d161c9866876410374b00b5803 Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:21:22 +1000 Subject: [PATCH 3/8] Added change log entry --- user_docs/en/changes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index eb318fa7f1e..a1f31e6919b 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -17,6 +17,7 @@ The available options are: * The timeout to perform a multiple keypress is now configurable; this may be especially useful for people with dexterity impairment. (#11929, @CyrilleB79) * When performing a braille cursor routing action, NVDA can now automatically speak the character at the cursor. (#8072, @LeonarddeR) * This option is disabled by default. You can enable "Speak character when routing cursor in text" in NVDA's braille settings. +* It is now possible to use braille display routing keys to move the text cursor in Microsoft PowerPoint. (#9101) ### Changes From 08d76eb64343cd437835bc7e87ab727552d89188 Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:45:39 +1000 Subject: [PATCH 4/8] Added _setSelectionOffsets method in TextFrameTextInfo, making NVDA's selection commands (NVDA+F9/F10) work in PowerPoint. --- source/appModules/powerpnt.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/appModules/powerpnt.py b/source/appModules/powerpnt.py index d4160f50611..a3642340ef4 100644 --- a/source/appModules/powerpnt.py +++ b/source/appModules/powerpnt.py @@ -1136,6 +1136,25 @@ def _setCaretOffset(self, offset: int): # The TextRange.characters method is 1-indexed. self.obj.ppObject.textRange.characters(offset + 1, 0).select() + def _setSelectionOffsets(self, start: int, end: int): + if not start < end: + log.debug(f"start must be less than end. Got {start=}, {end=}.", stack_info=True) + return + maxLength = self._getStoryLength() + # Having start = maxLength does not make sense, as there will be no selection if this is the case. + if not 0 <= start < maxLength: + log.debugWarning( + f"Got out of range {start=} (min 0, max {maxLength - 1}. Clamping.", + stack_info=True, + ) + start = max(0, min(start, maxLength - 1)) + # Having end = 0 does not make sense, as there will be no selection if this is the case. + if not 0 < end <= maxLength: + log.debugWarning(f"Got out of range {end=} (min 1, max {maxLength}. Clamping.", stack_info=True) + end = max(1, min(end, maxLength)) + # The TextRange.characters method is 1-indexed. + self.obj.ppObject.textRange.characters(start + 1, end - start).select() + class Table(Shape): """Represents the table shape in Powerpoint. Provides row and column counts.""" From 10ea42aad773da7968d188dd9bd8ac662217df7c Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:52:15 +1000 Subject: [PATCH 5/8] Fixed a typo --- source/appModules/powerpnt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/appModules/powerpnt.py b/source/appModules/powerpnt.py index a3642340ef4..b154f379e72 100644 --- a/source/appModules/powerpnt.py +++ b/source/appModules/powerpnt.py @@ -1130,7 +1130,10 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True) def _setCaretOffset(self, offset: int): if not 0 <= offset <= (maxLength := self._getStoryLength()): - log.debugWarning(f"Got out of range {offset=} (min 0, max {maxLength}. Clamping.", stack_inf=True) + log.debugWarning( + f"Got out of range {offset=} (min 0, max {maxLength}. Clamping.", + stack_info=True, + ) offset = max(0, min(offset, maxLength)) # Use the TextRange.select method to move the text caret to a 0-length TextRange. # The TextRange.characters method is 1-indexed. From 4728637cf782dc95d4ba9a8f7cefa5533fbec75a Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:56:03 +1000 Subject: [PATCH 6/8] Updated change log --- user_docs/en/changes.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index a1f31e6919b..83e1dca4908 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -17,7 +17,9 @@ The available options are: * The timeout to perform a multiple keypress is now configurable; this may be especially useful for people with dexterity impairment. (#11929, @CyrilleB79) * When performing a braille cursor routing action, NVDA can now automatically speak the character at the cursor. (#8072, @LeonarddeR) * This option is disabled by default. You can enable "Speak character when routing cursor in text" in NVDA's braille settings. -* It is now possible to use braille display routing keys to move the text cursor in Microsoft PowerPoint. (#9101) +* Improvements in PowerPoint: (#17004) + * It is now possible to use braille display routing keys to move the text cursor in Microsoft PowerPoint. (#9101) + * It is now possible to use NVDA's review cursor selection commands to select text in Microsoft PowerPoint. ### Changes From c20fa4a0f689fb397bb380b7b502bb94ea3c54ae Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:17:47 +1000 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Sean Budd --- source/appModules/powerpnt.py | 6 +++--- user_docs/en/changes.md | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/appModules/powerpnt.py b/source/appModules/powerpnt.py index b154f379e72..93cd651a901 100644 --- a/source/appModules/powerpnt.py +++ b/source/appModules/powerpnt.py @@ -1129,7 +1129,7 @@ def _getFormatFieldAndOffsets(self, offset, formatConfig, calculateOffsets=True) return formatField, (startOffset, endOffset) def _setCaretOffset(self, offset: int): - if not 0 <= offset <= (maxLength := self._getStoryLength()): + if not (0 <= offset <= (maxLength := self._getStoryLength())): log.debugWarning( f"Got out of range {offset=} (min 0, max {maxLength}. Clamping.", stack_info=True, @@ -1145,14 +1145,14 @@ def _setSelectionOffsets(self, start: int, end: int): return maxLength = self._getStoryLength() # Having start = maxLength does not make sense, as there will be no selection if this is the case. - if not 0 <= start < maxLength: + if not (0 <= start < maxLength): log.debugWarning( f"Got out of range {start=} (min 0, max {maxLength - 1}. Clamping.", stack_info=True, ) start = max(0, min(start, maxLength - 1)) # Having end = 0 does not make sense, as there will be no selection if this is the case. - if not 0 < end <= maxLength: + if not (0 < end <= maxLength): log.debugWarning(f"Got out of range {end=} (min 1, max {maxLength}. Clamping.", stack_info=True) end = max(1, min(end, maxLength)) # The TextRange.characters method is 1-indexed. diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index 83e1dca4908..1568de341b0 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -18,8 +18,8 @@ The available options are: * When performing a braille cursor routing action, NVDA can now automatically speak the character at the cursor. (#8072, @LeonarddeR) * This option is disabled by default. You can enable "Speak character when routing cursor in text" in NVDA's braille settings. * Improvements in PowerPoint: (#17004) - * It is now possible to use braille display routing keys to move the text cursor in Microsoft PowerPoint. (#9101) - * It is now possible to use NVDA's review cursor selection commands to select text in Microsoft PowerPoint. + * It is now possible to use braille display routing keys to move the text cursor. (#9101) + * It is now possible to use the review cursor selection commands to select text. ### Changes From 36300e3b8ea9f601d8cb2b41e8472522e13cdf93 Mon Sep 17 00:00:00 2001 From: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:24:56 +1000 Subject: [PATCH 8/8] Moved changes to bug fixes section --- user_docs/en/changes.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index 1568de341b0..b167b4d032f 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -17,9 +17,6 @@ The available options are: * The timeout to perform a multiple keypress is now configurable; this may be especially useful for people with dexterity impairment. (#11929, @CyrilleB79) * When performing a braille cursor routing action, NVDA can now automatically speak the character at the cursor. (#8072, @LeonarddeR) * This option is disabled by default. You can enable "Speak character when routing cursor in text" in NVDA's braille settings. -* Improvements in PowerPoint: (#17004) - * It is now possible to use braille display routing keys to move the text cursor. (#9101) - * It is now possible to use the review cursor selection commands to select text. ### Changes @@ -41,6 +38,9 @@ The available options are: * NVDA no longer throws an error when panning the braille display forward in some empty edit controls. (#16927) * NVDA no longer occasionally fails to open browsable messages (such as pressing `NVDA+f` twice). (#16806, @LeonarddeR) * NVDA is no longer unstable after restarting NVDA during an automatic Braille Bluetooth scan. (#16933) +* Improvements in Microsoft PowerPoint: (#17004) + * It is now possible to use braille display routing keys to move the text cursor. (#9101) + * It is now possible to use the review cursor selection commands to select text. ### Changes for Developers