Correctly read blank cells in MS Word with NVDA's UIA for MS Word option enabled#12731
Conversation
…play, don't call GetTextWithFields for any textInfo that is collapsed, otherwise in some circomstances such as in MS word with UIA enabled, fields may be repeated.
…g to any text unit when on a blank table cell causes the text range to expand onto the end-of-cell marker and also not treat the range as being inside the cell, causing NVDA to not announce the current row and column and think it is outside the table.
| fields = None | ||
| if not self.isCollapsed: | ||
| rawText = self._rangeObj.GetText(2) | ||
| if not rawText or rawText == '\x07': |
There was a problem hiding this comment.
What does '\x07' represent in this instance? Could it be replaced by a named constant?
LeonarddeR
left a comment
There was a problem hiding this comment.
Thanks, I really dig this!
| fields=super(WordDocumentTextInfo,self).getTextWithFields(formatConfig=formatConfig) | ||
| fields = None | ||
| if not self.isCollapsed: | ||
| rawText = self._rangeObj.GetText(2) |
There was a problem hiding this comment.
Why getting 2 characters here instead of just one?
There was a problem hiding this comment.
Fetching 2 characters ensures that that the range does not deliberately span past the end of the cell and into the next cell and or out of the table. I've added a detailed code comment to the change now.
| r.end = r.start | ||
| fields = super(WordDocumentTextInfo, r).getTextWithFields(formatConfig=formatConfig) | ||
| if fields is None: | ||
| fields = super(WordDocumentTextInfo, self).getTextWithFields(formatConfig=formatConfig) |
There was a problem hiding this comment.
Might as well make this new style super. That also creates a bigger contrast with the super call abbove, that calls super on r.
| fields = super(WordDocumentTextInfo, self).getTextWithFields(formatConfig=formatConfig) | |
| fields = super().getTextWithFields(formatConfig=formatConfig) |
|
Thank you very much! I have been waiting for this for a long time |
Link to issue number:
Fixes #11043
Fixes #11457
Fixes #12490
Summary of the issue:
When using UIA to access Microsoft word documents with NVDA, NVDA failed to announce row and column numbers when arrowing onto blank table cells. Also, navigating a table with the control+alt+arrow keys and landing on blank cells would sometimes announce leaving the table.
This was caused by the fact that when expanding a IUIAutomationTextRange in a blank table cell to any text unit, the range will cover the end-of-cell marker, and therefore span more than the cell itself, thus it looks like the range is not entirely inside the cell.
Description of how this pull request fixes the issue:
Work around this MS Word bug by detecting when in this situation: the range is not collapsed, yet the text in the range is either empty or the end-of-cell marker. And if so, Use a copy of the range, that is collapsed to the start (entirely inside the cell) to fetch the text and fields.
This pr also makes a change to Braille, so that when building a line of rich text in braille, a TextInfo's getTextWithFields method is only called if the textInfo is not collapsed. this stops repeating of fields for collapsed ranges, which was sometimes seen in Microsoft Word with UIA enabled.
Testing strategy:
Navigated a Word document containing tables, lists, headings, images, comments, foot notes and end notes, ensuring that noting has changed in speech or braille. Test document:
Test document.docx
Create a new document in MS Word, insert a blank table, and use, arrows, tab and control+alt+arrows to move between the blank cells ensuring that row and column info is reported in both speech and braille.
Known issues with pull request:
None known.
Change log entries:
Bug fixes
Code Review Checklist: