Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS Word: The result of Word commands to expand or collapse a heading is now reported #17545

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions source/appModules/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@
import appModuleHandler
from scriptHandler import script
import ui
from logHandler import log
from NVDAObjects.IAccessible.winword import WordDocument as IAccessibleWordDocument
from NVDAObjects.UIA.wordDocument import WordDocument as UIAWordDocument
from NVDAObjects.window.winword import WordDocument
from utils.displayString import DisplayStringIntEnum
from typing import TYPE_CHECKING

if TYPE_CHECKING:
import inputCore


# From WdOutlineLevel enumeration
# See https://learn.microsoft.com/fr-fr/office/vba/api/word.wdoutlinelevel
wdOutlineLevelBodyText = 10


class ViewType(DisplayStringIntEnum):
Expand Down Expand Up @@ -79,6 +89,39 @@ def script_toggleChangeTracking(self, gesture):
# Translators: a message when toggling change tracking in Microsoft word
ui.message(_("Change tracking off"))

@script(gestures=["kb:alt+shift+-", "kb:alt+shift+="])
def script_collapseOrExpandHeading(self, gesture: "inputCore.InputGesture"):
if not self.WinwordSelectionObject:
# We cannot fetch the Word object model, so we therefore cannot report the format change.
# The object model may be unavailable because this is a pure UIA implementation such as Windows 10 Mail,
# or it's within Windows Defender Application Guard.
# In this case, just let the gesture through and don't report anything.
return gesture.send()
maxParagraphs = 50
for nParagraph, paragraph in enumerate(self.WinwordSelectionObject.paragraphs):
if paragraph.outlineLevel != wdOutlineLevelBodyText:
break
if nParagraph >= maxParagraphs:
log.debugWarning("Too many paragraphs selected")
gesture.send()
return
else:
gesture.send()
# Translators: a message when collapsing or expanding headings in MS Word
ui.message(_("No heading selected"))
return
val = self._WaitForValueChangeForAction(
lambda: gesture.send(),
lambda: paragraph.CollapsedState,
)
if val:
# Translators: a message when collapsing a heading in MS Word
msg = _("Collapsed")
else:
# Translators: a message when expanding a heading in MS Word
msg = _("Expanded")
ui.message(msg)

__gestures = {
"kb:control+shift+b": "toggleBold",
"kb:control+shift+w": "toggleUnderline",
Expand Down
4 changes: 3 additions & 1 deletion user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ To use this feature, "allow NVDA to control the volume of other applications" mu
* It now starts with a more user friendly explanation of its purpose, instead of a warning. (#12351)
* The initial window can now be exited with `escape` or `alt+f4`. (#10799)
* 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.
* In Word and Outlook the result of more font formatting shortcuts is now reported. (#10271, @CyrilleB79)
* In Word and Outlook the result of more shortcuts is reported:
* font formatting shortcuts (#10271, @CyrilleB79)
* Collapse or expand heading (#17545, @CyrilleB79)
* Default input and output braille tables can now be determined based on the NVDA language. (#17306, #16390, #290, @nvdaes)
* 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)
* 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)
Expand Down