Skip to content

MS Word: allow reporting distance from left and top edges of page with report location of review cursor command#8814

Merged
michaelDCurran merged 4 commits into
masterfrom
i1939
Oct 4, 2018
Merged

MS Word: allow reporting distance from left and top edges of page with report location of review cursor command#8814
michaelDCurran merged 4 commits into
masterfrom
i1939

Conversation

@michaelDCurran

Copy link
Copy Markdown
Member

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.

…h report location of review cursor command: NVDA+numpadDelete.
Comment thread source/NVDAObjects/window/winword.py Outdated
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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two spaces between left and edge.


def _get_locationText(self):
rects=self._rangeObj.getBoundingRectangles()
left=rects[0]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Copy the text info
  2. If self.obj.isTextSelectionAnchoredAtStart, than collapse the copy to the end of the range. Collapse to the start otherwise
  3. Now, you can safely get a bounding rectangle.

See also #8572, which implements a boundingRect property which we can use in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, agreed.

class WordDocumentTextInfo(UIATextInfo):

def _get_locationText(self):
rects=self._rangeObj.getBoundingRectangles()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nvdaes

nvdaes commented Oct 3, 2018

Copy link
Copy Markdown
Collaborator

Thanks so much. I've send the link to this PR to the mentioned spanish mailing list at
https://nvdaes.groups.io/g/lista/message/319

Hope this can be merged soon :)

Congrats for your great work as developers and reviewers. I'm impressed for your quick response.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed something pretty important

Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
# 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, missed this one. This is actually not caught in script_navigatorObject_currentDimensions. You do want to return super here instead.

Comment thread source/NVDAObjects/UIA/wordDocument.py Outdated
r=om.rangeFromPoint(left,top)
except (COMError,NameError):
log.debugWarning("MS Word object model does not support rangeFromPoint")
raise NotImplementedError

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@LeonarddeR LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@michaelDCurran

michaelDCurran commented Oct 4, 2018 via email

Copy link
Copy Markdown
Member Author

@nvdaes

nvdaes commented Oct 4, 2018

Copy link
Copy Markdown
Collaborator

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.

@nvdaes

nvdaes commented Oct 4, 2018

Copy link
Copy Markdown
Collaborator

For me is OK like that if you want to merge this without mentioning laptop keyboard, it was just a suggestion, non meaningful.
This is great!

@michaelDCurran michaelDCurran merged commit 850e10a into master Oct 4, 2018
@nvaccessAuto nvaccessAuto added this to the 2018.4 milestone Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Word 2010: need a way to query cursor position, i.e. how many inches from margin - very useful for formatting

4 participants