Skip to content

Commit 7e57e51

Browse files
authored
Merge 2721d47 into 782c3d8
2 parents 782c3d8 + 2721d47 commit 7e57e51

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

source/appModules/winword.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
from utils.displayString import DisplayStringIntEnum
1818

1919

20+
# From WdOutlineLevel enumeration
21+
# See https://learn.microsoft.com/fr-fr/office/vba/api/word.wdoutlinelevel
22+
wdOutlineLevelBodyText = 10
23+
24+
2025
class ViewType(DisplayStringIntEnum):
2126
"""Enumeration containing the possible view types in Word documents:.
2227
https://learn.microsoft.com/en-us/office/vba/api/word.wdviewtype
@@ -79,6 +84,39 @@ def script_toggleChangeTracking(self, gesture):
7984
# Translators: a message when toggling change tracking in Microsoft word
8085
ui.message(_("Change tracking off"))
8186

87+
@script(gestures=["kb:alt+shift+-", "kb:alt+shift+="])
88+
def script_collapseOrExpandHeading(self, gesture: "inputCore.InputGesture"):
89+
if not self.WinwordSelectionObject:
90+
# We cannot fetch the Word object model, so we therefore cannot report the format change.
91+
# The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
92+
# or it's within Windows Defender Application Guard.
93+
# In this case, just let the gesture through and don't report anything.
94+
return gesture.send()
95+
maxParagraphs = 50
96+
for nParagraph, paragraph in enumerate(self.WinwordSelectionObject.paragraphs):
97+
if paragraph.outlineLevel != wdOutlineLevelBodyText:
98+
break
99+
if nParagraph >= maxParagraphs:
100+
log.debugWarning("Too many paragraphs selected")
101+
gesture.send()
102+
return
103+
else:
104+
gesture.send()
105+
# Translators: a message when collapsing or expanding headings in MS Word
106+
ui.message(_("No heading selected"))
107+
return
108+
val = self._WaitForValueChangeForAction(
109+
lambda: gesture.send(),
110+
lambda: paragraph.CollapsedState,
111+
)
112+
if val:
113+
# Translators: a message when collapsing a heading in MS Word
114+
msg = _("Collapsed")
115+
else:
116+
# Translators: a message when expanding a heading in MS Word
117+
msg = _("Expanded")
118+
ui.message(msg)
119+
82120
__gestures = {
83121
"kb:control+shift+b": "toggleBold",
84122
"kb:control+shift+w": "toggleUnderline",

user_docs/en/changes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ To use this feature, "allow NVDA to control the volume of other applications" mu
3838
* It now starts with a more user friendly explanation of its purpose, instead of a warning. (#12351)
3939
* The initial window can now be exited with `escape` or `alt+f4`. (#10799)
4040
* It will now show a message to the user, including the error, in the rare event of a Windows error while attempting COM re-registrations.
41-
* In Word and Outlook the result of more font formatting shortcuts is now reported. (#10271, @CyrilleB79)
41+
* In Word and Outlook the result of more shortcuts is reported:
42+
* font formatting shortcuts (#10271, @CyrilleB79)
43+
* Collapse or expand heading (#17545, @CyrilleB79)
4244
* Default input and output braille tables can now be determined based on the NVDA language. (#17306, #16390, #290, @nvdaes)
4345
* In Microsoft Word, when using the "report focus" command, the document layout will be announced if this information is available and reporting object descriptions is enabled. (#15088, @nvdaes)
4446
* NVDA will now only warn about add-on incompatibility when updating to a version which has an incompatible add-on API to the currently installed copy. (#17071, #17506)

0 commit comments

Comments
 (0)