Repository: nvaccess/nvda

Issue:
Error when using LibreOffice Writer
<!-- 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/blob/master/devDocs/githubIssueTemplateExplanationAndExamples.md
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. 

Each of the questions and sections below start with multiple hash symbols (#). Place your answers and information on the blank line below each question.
-->

### Steps to reproduce:
Open LibreOffice Writer and try to write some text.

### Actual behavior:
NVDA does not see nor the text neither the cursor position.

### Expected behavior:
We should be able to review the document.

### System configuration

#### NVDA installed/portable/running from source:
NVDA installed

#### NVDA version:
alpha-23903,fb4466ee

#### Windows version:
Windows 10 21H2 64 bits

#### Name and version of other software in use when reproducing the issue:
LibreOffice 7.2.1 64 bits

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your computer?

#### Have you tried any other versions of NVDA? If so, please report their behaviors.

#### If NVDA add-ons are disabled, is your problem still occurring?

#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?



Discussion:
Confirmed with latest Alpha.
When moving with up and down arrows 'blank' is reported. With left and right error sound plays, and the following is in the log:
```
error executing script: <bound method EditableText.script_caret_moveByCharacter of <compoundDocuments.CompoundDocument object at 0x073B3630>> with gesture 'left arrow'
Traceback (most recent call last):
  File "scriptHandler.pyc", line 208, in executeScript
  File "editableText.pyc", line 228, in script_caret_moveByCharacter
  File "editableText.pyc", line 163, in _caretMovementScriptHelper
  File "editableText.pyc", line 149, in _caretScriptPostMovedHelper
  File "speech\speech.pyc", line 1138, in speakTextInfo
  File "speech\types.pyc", line 42, in __iter__
  File "speech\speech.pyc", line 1335, in getTextInfoSpeech
AttributeError: 'NoneType' object has no attribute 'isspace'

```

This does not occur with 2021.2.
Notes for developer looking at this:
- See revision 627673b63ff883de9aad6aea982ccb1354309663
- Investigate why  `textWithFields[0]` is None
- Note PR #12710 which will remove this line
Is there a chance this could be repaired for 2021.3?
@MichelSuch we are looking into it. The list of issues that are blocking the release can be found by looking at [the 2021.3 milestone](https://github.com/nvaccess/nvda/milestone/57), currently it is just this issue.


Resolving patch:
diff --git a/source/compoundDocuments.py b/source/compoundDocuments.py
--- a/source/compoundDocuments.py
+++ b/source/compoundDocuments.py
@@ -136,7 +136,7 @@ def _isNamedlinkDestination(self, obj: NVDAObject) -> bool:
 			and controlTypes.State.LINKED not in obj.states
 		)
 
-	def _getControlFieldForObject(self, obj, ignoreEditableText=True):
+	def _getControlFieldForObject(self, obj: NVDAObject, ignoreEditableText=True):
 		if ignoreEditableText and self._isObjectEditableText(obj):
 			# This is basically just a text node.
 			return None
@@ -290,16 +290,18 @@ def getTextWithFields(self, formatConfig=None):
 						embedIndex = self._getFirstEmbedIndex(ti)
 					else:
 						embedIndex += 1
-					field = ti.obj.getChild(embedIndex)
-					controlField = self._getControlFieldForObject(field, ignoreEditableText=False)
-					controlField["content"] = field.name
+					childObject: NVDAObject = ti.obj.getChild(embedIndex)
+					controlField = self._getControlFieldForObject(childObject, ignoreEditableText=False)
+					controlField["content"] = childObject.name
 					fields.extend((
 						textInfos.FieldCommand("controlStart", controlField),
 						textUtils.OBJ_REPLACEMENT_CHAR,
 						textInfos.FieldCommand("controlEnd", None)
 					))
-				else:
-					fields.append(field)
+				else:  # str or fieldCommand
+					if not isinstance(textWithEmbeddedObjectsItem, (str, textInfos.FieldCommand)):
+						log.error(f"Unexpected type: {textWithEmbeddedObjectsItem!r}")
+					fields.append(textWithEmbeddedObjectsItem)
 		return fields
 
 	def _findNextContent(self, origin, moveBack=False):


Test patch: