MS Word with UIA: heading quicknav no longer keeps repeating the last heading#13013
Conversation
…ch the algorithm in UIATextAttributeQuicknavIterator, so as to stop yielding the final heading of a document twice. It now loops using iterUIARangeByUnit, rather than manually moving through the range.
|
Would it help to do some timings with huge documents with many headings to see how performance is affected? |
|
To test timing: |
|
Wow, these are the timings I was hoping for! |
| @@ -152,27 +152,34 @@ def isChild(self,parent): | |||
| return self.level>parent.level | |||
|
|
|||
| def UIAHeadingQuicknavIterator(itemType,document,position,direction="next"): | |||
There was a problem hiding this comment.
Would you be able to add type hints? See below
Check for None rather than if not Co-authored-by: Leonard de Ruijter <leonardder@users.noreply.github.com>
| curPosition=position | ||
| reverse = bool(direction == "previous") | ||
| entireDocument = document.makeTextInfo(textInfos.POSITION_ALL) | ||
| if position is None: |
There was a problem hiding this comment.
@LeonarddeR position will be None if called by the Elements list to list all headings. Position is a TextInfo if called by quicknav to jump from a specific location.
Link to issue number:
Fixes #9540
Summary of the issue:
When accessing MS Word documents with UIA, if the last bit of text is formatted as a heading, pressing quicknav by heading (h) in browse mode keeps repeating that heding. Similarly, The elements list when set to show headings, lists the final heading twice.
This is due to the fact that most UIA providers when on the last unit, move to the collapsed exclusive end if asked to move forward 1 by that unit. Only after that does the move fail.
We could add some specific checks in the UIABrowseMode.UIAHeadingQuicknavIterator function to take this into account, or we can rewrite that algorithm to make use of iterUIARangeByUnit which is used in many other places and avoids that bug all together.
Description of how this pull request fixes the issue:
Rewrite the UIABrowseMode.UIAHeadingQuicknavIterator function to make use of iterUIARangeByUnit. It is now much more similar to the UIABrowseMode.UIATextAttributeQuicknavIterator function, which we know does not have the repeating bug.
Testing strategy:
Testand press enterFirst headingand press enterTestand press enterSecond headingand press enterSecond headingshould be the final line of text in the document, I.e. the heading ends at the end of the document.First headingSecond headingFirst headingFirst headingandSecond heading.Known issues with pull request:
None known.
Change log entries:
New features
Changes
Bug fixes
For Developers
Code Review Checklist: