Repository: nvaccess/nvda

Issue:
NVDA+f7 does not bring up elements list in Word initially (2020.4rc1)
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 
-->

### Is your feature request related to a problem? Please describe.

In NVDA 2020.4, the elements list can now be opened in focus mode as well as browse mode, per issue #10453

In Word, this does not work initially:

1) Open Word to a blank document.
2) Press NVDA+f7 to open the elements list
3) Press ESCAPE
4) Press NVDA+spacebar twice to change NVDA to browse mode and back to focus mode
5) Press NVDA+f7 to open the elements list.

At step 2, instead of the elements list, Word's spell check opens (the NVDA log confirms NVDA+F7 was pressed.  No error or anything odd is recorded at debug level, it just behaves exactly as if F7 had been pressed).

At step 5, the elements list opens as expected.

### Describe the solution you'd like

The elements list should open at Step 2 as expected.

### Describe alternatives you've considered

### Additional context



Discussion:

Resolving patch:
diff --git a/source/NVDAObjects/IAccessible/winword.py b/source/NVDAObjects/IAccessible/winword.py
--- a/source/NVDAObjects/IAccessible/winword.py
+++ b/source/NVDAObjects/IAccessible/winword.py
@@ -21,11 +21,14 @@
 from NVDAObjects.window import DisplayModelEditableText
 from ..behaviors import EditableTextWithoutAutoSelectDetection
 from NVDAObjects.window.winword import *
+from NVDAObjects.window.winword import WordDocumentTreeInterceptor
+
 
 class WordDocument(IAccessible,EditableTextWithoutAutoSelectDetection,WordDocument):
  
-	treeInterceptorClass=WordDocumentTreeInterceptor
-	shouldCreateTreeInterceptor=False
+	treeInterceptorClass = WordDocumentTreeInterceptor
+	shouldCreateTreeInterceptor = True
+
 	TextInfo=WordDocumentTextInfo
 
 	def _get_ignoreEditorRevisions(self):
diff --git a/source/NVDAObjects/UIA/wordDocument.py b/source/NVDAObjects/UIA/wordDocument.py
--- a/source/NVDAObjects/UIA/wordDocument.py
+++ b/source/NVDAObjects/UIA/wordDocument.py
@@ -298,6 +298,14 @@ def getTextWithFields(self,formatConfig=None):
 
 class WordBrowseModeDocument(UIABrowseModeDocument):
 
+	# This treeInterceptor starts in focus mode, thus escape should not switch back to browse mode
+	disableAutoPassThrough = True
+
+	def __init__(self, rootNVDAObject):
+		super(WordBrowseModeDocument, self).__init__(rootNVDAObject)
+		self.passThrough = True
+		browseMode.reportPassThrough.last = True
+
 	def shouldSetFocusToObj(self,obj):
 		# Ignore strange editable text fields surrounding most inner fields (links, table cells etc) 
 		if obj.role==controlTypes.ROLE_EDITABLETEXT and obj.UIAElement.cachedAutomationID.startswith('UIA_AutomationId_Word_Content'):
@@ -341,8 +349,8 @@ def _get_role(self):
 		return role
 
 class WordDocument(UIADocumentWithTableNavigation,WordDocumentNode,WordDocumentBase):
-	treeInterceptorClass=WordBrowseModeDocument
-	shouldCreateTreeInterceptor=False
+	treeInterceptorClass = WordBrowseModeDocument
+	shouldCreateTreeInterceptor = True
 	announceEntireNewLine=True
 
 	# Microsoft Word duplicates the full title of the document on this control, which is redundant as it appears in the title of the app itself.
diff --git a/source/NVDAObjects/window/winword.py b/source/NVDAObjects/window/winword.py
--- a/source/NVDAObjects/window/winword.py
+++ b/source/NVDAObjects/window/winword.py
@@ -1069,6 +1069,14 @@ def _get_focusableNVDAObjectAtStart(self):
 
 class WordDocumentTreeInterceptor(browseMode.BrowseModeDocumentTreeInterceptor):
 
+	# This treeInterceptor starts in focus mode, thus escape should not switch back to browse mode
+	disableAutoPassThrough = True
+
+	def __init__(self, rootNVDAObject):
+		super(WordDocumentTreeInterceptor, self).__init__(rootNVDAObject)
+		self.passThrough = True
+		browseMode.reportPassThrough.last = True
+
 	TextInfo=BrowseModeWordDocumentTextInfo
 
 	def _activateLongDesc(self,controlField):


Test patch: