MS Word: allow reporting distance from left and top edges of page with report location of review cursor command#8814
Conversation
…h report location of review cursor command: NVDA+numpadDelete.
| offset=self._rangeObj.information(wdHorizontalPositionRelativeToPage) | ||
| distance=self.obj.getLocalizedMeasurementTextForPointSize(offset) | ||
| # Translators: a distance from the left edge of the page in Microsoft Word | ||
| textList.append(_("{distance} from left edge of page").format(distance=distance)) |
There was a problem hiding this comment.
Two spaces between left and edge.
|
|
||
| def _get_locationText(self): | ||
| rects=self._rangeObj.getBoundingRectangles() | ||
| left=rects[0] |
There was a problem hiding this comment.
This is going to fail in case of selections that are anchored at the start, in which case this will report the distances for the start, not for the cursor position.
I think you want to do something like this:
- Copy the text info
- If self.obj.isTextSelectionAnchoredAtStart, than collapse the copy to the end of the range. Collapse to the start otherwise
- Now, you can safely get a bounding rectangle.
See also #8572, which implements a boundingRect property which we can use in the future.
There was a problem hiding this comment.
In the specific case this pr is for, locationText is only ever called on a collapsed textInfo at the reviewCursor position. Whether the reviewCursor is positioned at the correct end of the selection is somewhat a separate issue.
| class WordDocumentTextInfo(UIATextInfo): | ||
|
|
||
| def _get_locationText(self): | ||
| rects=self._rangeObj.getBoundingRectangles() |
There was a problem hiding this comment.
Have you actually considered abstracting this into a method that will try to get a WordDocumentTextInfo based on the location of the UIA info? Could be beneficial for other features that are supported in the object model while not yet available in UIA. I guess it is ok to leave this pr as is now, though.
|
Thanks so much. I've send the link to this PR to the mentioned spanish mailing list at Hope this can be merged soon :) Congrats for your great work as developers and reviewers. I'm impressed for your quick response. |
LeonarddeR
left a comment
There was a problem hiding this comment.
Sorry, missed something pretty important
| # Therefore for now, get the screen coordinates, and if the word object model is available, use our legacy code to get the location text. | ||
| om=self.obj.WinwordWindowObject | ||
| if not om: | ||
| raise NotImplementedError |
There was a problem hiding this comment.
Woops, missed this one. This is actually not caught in script_navigatorObject_currentDimensions. You do want to return super here instead.
| r=om.rangeFromPoint(left,top) | ||
| except (COMError,NameError): | ||
| log.debugWarning("MS Word object model does not support rangeFromPoint") | ||
| raise NotImplementedError |
LeonarddeR
left a comment
There was a problem hiding this comment.
Could you please return super instead as I requested? In the current situation, that will just say None, but in case locationText will be implemented on a parent, that information will be returned instead.
|
That is fair enough. I have made the change now.
|
|
Should be mentioned that the keystroke for laptop keyboard is NVD+delete, not NVDA+numpadDelete? I'm a user of laptop keyboard even when I'm working ind tesktop computers and maybe clear. |
|
For me is OK like that if you want to merge this without mentioning laptop keyboard, it was just a suggestion, non meaningful. |
Link to issue number:
Fixes #1939
Summary of the issue:
When creating Word documents, it can be sometimes useful to know the distance from the edge of the page.
NVDA does not currently have any way to report this information.
Description of how this pull request fixes the issue:
Provide an implementation of the locationText property on both Word document TextInfo classes (object model, and UIA) that returns a string stating the distance of the cursor from the left and top of the page, in user-configured units (E.g. inches, centimetres).
This allows the user to report the distances by pressing NVDA+numpadDelete (report review cursor location command).
As UI Automation does not currently provide a way to find out the actual distance from the edge of a page, this code falls back to using the Word object model if available. Thus, this feature will not work in Windows 10 Mail for instance.
Testing performed:
In a word document, moved the cursor to various lines and offsets within those lines, and reported the distances by pressing NVDA+numpadDelete.
Known issues with pull request:
None.
Change log entry:
Already in pr.