Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the review cursor to be bounded to onscreen text #9735

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7a123c3
Remove bounds checking code from the console.
codeofdusk Jun 13, 2019
a61dab0
Implement isOutOfBounds.
codeofdusk Jun 13, 2019
a8b93bd
Implement review bounds configuration.
codeofdusk Jun 13, 2019
6bb21b2
Fix isOutOfBounds for UIA, implement initial bounds checking, and bou…
codeofdusk Jun 13, 2019
deffcea
Implement review of top and bottom lines when review is bounded.
codeofdusk Jun 13, 2019
51fa56a
Add new gesture to the input gestures dialog, update user guide.
codeofdusk Jun 13, 2019
a1ad305
Implement review bounds configuration for offsetsTextInfo.
codeofdusk Jun 13, 2019
d7a00e8
Apply suggestions from code review
codeofdusk Jun 13, 2019
1a937d2
Review actions.
codeofdusk Jun 13, 2019
536ccce
isOutOfBounds -> isOffscreen
codeofdusk Jun 13, 2019
d84570a
Move SCRCAT constants to a new scriptCategories module.
codeofdusk Jun 13, 2019
4540972
Review actions.
codeofdusk Jun 18, 2019
b7126db
Merge branch 'master' into reviewbounds
codeofdusk Jun 18, 2019
0f41ef3
Merge branch 'master' into reviewbounds
codeofdusk Jun 18, 2019
768cf6b
Clarify doc comment.
codeofdusk Jun 18, 2019
4cc443f
Add unique IDs for NVDA objects.
codeofdusk Jun 20, 2019
291b00e
Persist review bounds state when an object is regenerated.
codeofdusk Jun 20, 2019
c94229b
Make isOffscreen a property.
codeofdusk Jun 20, 2019
b2924fa
Fixes.
codeofdusk Jun 21, 2019
2c24358
Better default review bounds configuration for objects.
codeofdusk Jun 21, 2019
959a6c7
Remove unneeded import.
codeofdusk Jun 21, 2019
360ce53
Merge branch 'master' into reviewbounds
codeofdusk Jun 21, 2019
7146fae
Merge branch 'master' into reviewbounds
codeofdusk Jul 7, 2019
2f85736
Merge branch 'master' into reviewbounds
codeofdusk Jul 16, 2019
87d67e7
Revert "Add unique IDs for NVDA objects."
codeofdusk Jul 16, 2019
d41476b
Revert "Persist review bounds state when an object is regenerated."
codeofdusk Jul 16, 2019
8c50383
Revert "Better default review bounds configuration for objects."
codeofdusk Jul 16, 2019
cf11cdd
Make review bounds state global and bound review by default where sup…
codeofdusk Jul 16, 2019
11f0d59
Disable bounds checking if we're currently offscreen to avoid getting…
codeofdusk Jul 17, 2019
bd33c92
In UIA consoles, diff the entire buffer instead of just the visible r…
codeofdusk Jul 17, 2019
f3ff4a2
Fix top/bottom review scripts.
codeofdusk Jul 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ def __init__(self,obj,position,_rangeObj=None):
elif position==textInfos.POSITION_LAST:
self._rangeObj=self.obj.UIATextPattern.documentRange
self.collapse(True)
elif position==textInfos.POSITION_FIRSTVISIBLE:
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
try:
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
self._rangeObj = visiRanges.GetElement(0)
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

This call should use element, not 0 I think.

except COMError:
# Error: FIRST_VISIBLE position not supported by the UIA text pattern.
Copy link
Member

Choose a reason for hiding this comment

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

The comment should reflect it is first or last position not supported, not just first.

raise RuntimeError
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
elif position==textInfos.POSITION_LASTVISIBLE:
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
try:
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
self._rangeObj = visiRanges.GetElement(visiRanges.length - 1)
except COMError:
# Error: LAST_VISIBLE position not supported by the UIA text pattern.
raise RuntimeError
elif position==textInfos.POSITION_ALL or position==self.obj:
self._rangeObj=self.obj.UIATextPattern.documentRange
elif isinstance(position,UIA) or isinstance(position,UIAHandler.IUIAutomationElement):
Expand Down Expand Up @@ -702,6 +716,22 @@ def compareEndPoints(self,other,which):
target=UIAHandler.TextPatternRangeEndpoint_End
return self._rangeObj.CompareEndpoints(src,other._rangeObj,target)

def isOutOfBounds(self):
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
Copy link
Member

Choose a reason for hiding this comment

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

Catch COMError around this call, raising NotImplementedError if so.

visiLength = visiRanges.length
if visiLength > 0:
firstVisiRange = visiRanges.GetElement(0)
lastVisiRange = visiRanges.GetElement(visiLength - 1)
return self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange,
UIAHandler.TextPatternRangeEndpoint_Start
) < 0 or self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange,
UIAHandler.TextPatternRangeEndpoint_End) >= 0
else:
# Review bounds not available.
return False
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved

def setEndPoint(self,other,which):
if which.startswith('start'):
src=UIAHandler.TextPatternRangeEndpoint_Start
Expand Down
30 changes: 4 additions & 26 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ def __init__(self, obj, position, _rangeObj=None):
)

def move(self, unit, direction, endPoint=None):
oldRange = None
if self.basePosition != textInfos.POSITION_CARET:
# Insure we haven't gone beyond the visible text.
# UIA adds thousands of blank lines to the end of the console.
visiRanges = self.obj.UIATextPattern.GetVisibleRanges()
visiLength = visiRanges.length
if visiLength > 0:
firstVisiRange = visiRanges.GetElement(0)
lastVisiRange = visiRanges.GetElement(visiLength - 1)
oldRange = self._rangeObj.clone()
if unit == textInfos.UNIT_WORD and direction != 0:
# UIA doesn't implement word movement, so we need to do it manually.
# Relative to the current line, calculate our offset
Expand Down Expand Up @@ -98,22 +88,7 @@ def move(self, unit, direction, endPoint=None):
endPoint=endPoint
)
else: # moving by a unit other than word
res = super(consoleUIATextInfo, self).move(unit, direction, endPoint)
if oldRange and (
self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start,
firstVisiRange,
UIAHandler.TextPatternRangeEndpoint_Start
) < 0
or self._rangeObj.CompareEndPoints(
UIAHandler.TextPatternRangeEndpoint_Start,
lastVisiRange,
UIAHandler.TextPatternRangeEndpoint_End
) >= 0
):
self._rangeObj = oldRange
return 0
return res
return super(consoleUIATextInfo, self).move(unit, direction, endPoint)

def expand(self, unit):
if unit == textInfos.UNIT_WORD:
Expand Down Expand Up @@ -200,6 +175,9 @@ def _get_focusRedirect(self):

class winConsoleUIA(Terminal):
STABILIZE_DELAY = 0.03
#: Bound review in consoles by default to maintain feature parity
#: with legacy
reviewBounded = True
_TextInfo = consoleUIATextInfo
_isTyping = False
_lastCharTime = 0
Expand Down
33 changes: 33 additions & 0 deletions source/NVDAObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
import weakref
from logHandler import log
from scriptHandler import script
import review
import eventHandler
from displayModel import DisplayModelTextInfo
Expand Down Expand Up @@ -1267,3 +1268,35 @@ def getSelectedItemsCount(self,maxCount=2):
For performance, this method will only count up to the given maxCount number, and if there is one more above that, then sys.maxint is returned stating that many items are selected.
"""
return 0

reviewBounded = False
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved

@script(gesture="kb:NVDA+o",
# Hardcoded to avoid circular import
category=_(u"Text review"),
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
# Translators: A gesture description.
description=_(u"Toggles whether review is constrained to the currently visible text"))
def script_toggleReviewBounds(self, gesture):
Copy link
Collaborator

Choose a reason for hiding this comment

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

It worries me that this is is on the object instead of a global command. Is there a particular reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I too think this could be cleaner as a global command, but the reviewBounded variable is also on the object so keeping this there might be better from an organizational standpoint...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Question is whether we really believe that review Bounded should be on the object or on the textInfo, or even global. If an object gets destroyed and created again, the state of review Bounded is lost. Having review bounds on tree interceptors also makes sense, i.e. when you want to review with document review what is on screen on a particular page.

I also think that it doesn't make much sense to have review bounds doing anything when in screen review. So in that case, the command should just do nothing.

Copy link
Member

Choose a reason for hiding this comment

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

I think it may have been my idea to put this on the object. but @LeonarddeR brings up a good point in that the state will be lost if moving away from the object and back again. The problem with having it global though is that different controls work best when reviewBounded is set in a specific way by default. I.e. consoles probably want it on by default.
Would we be comfortable having bounded on by default globally? I think this could work, but it would be a bit of a change to NvDA's behaviour. Probably a good change though. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, having this as a global default makes sense to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I also think a global default would be a plus.
It does not make much sense for a "screen" review to easily review what's not on screen.
It can be helpful at times, but is most often confusing when collaborating with a sighted person.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has now been made a global default.

try:
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
rp = api.getReviewPosition()
Copy link
Member

Choose a reason for hiding this comment

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

This line should be moved above the try block. Only isOffscreen is expected to throw NotImplementedError.

outOfBounds = rp.isOutOfBounds()
self.reviewBounded = not self.reviewBounded
if self.reviewBounded:
ui.message(
# Translators: Reported when review is constrained to this
# object's visible text.
_(u"Bounded review")
)
if outOfBounds:
api.setReviewPosition(
self.makeTextInfo(textInfos.POSITION_CARET), isCaret=True)
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why isCaret=True is necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the textInfo is a caret instance? Maybe it isn't needed...

else:
ui.message(
# Translators: Reported when review is unconstrained, so all
# of this object's text can be read.
_(u"Unbounded review")
)
except NotImplementedError:
ui.message(
# Translators: Reported when review bound configuration isn't supported for this object.
_(u"Not supported here"))
27 changes: 21 additions & 6 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,8 +972,21 @@ def script_review_activate(self,gesture):
script_review_activate.__doc__=_("Performs the default action on the current navigator object (example: presses it if it is a button).")
script_review_activate.category=SCRCAT_OBJECTNAVIGATION

def _moveWithBoundsChecking(self, info, unit, direction, endPoint=None):
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be moved into the base TextInfo class.
Also, is there a reason why this is non-distructive (I.e. returns a copy)? I don't think you actually ever make use of this. It could just do it distructively and return res like the other move... unless you have a particular plan for this not yet done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a generalization of the console's old bounds checking code (i.e. we captured an oldRange and didn't update the underlying UIA text range if a move was impossible). Would destructive be okay here?

"""
Nondestructively moves a textInfo and returns a (newInfo, res) tuple.
Res is 0 if the move would be out of bounds.
"""
newInfo = info.copy()
res = newInfo.move(unit, direction, endPoint=endPoint)
if newInfo.obj.reviewBounded and newInfo.isOutOfBounds():
return (info, 0)
return (newInfo, res)

def script_review_top(self,gesture):
info=api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_FIRST)
obj = api.getReviewPosition().obj
pos = textInfos.POSITION_FIRSTVISIBLE if obj.reviewBounded else textInfos.POSITION_FIRST
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
info = obj.makeTextInfo(pos)
api.setReviewPosition(info)
info.expand(textInfos.UNIT_LINE)
ui.reviewMessage(_("Top"))
Expand All @@ -987,7 +1000,7 @@ def script_review_previousLine(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_LINE)
info.collapse()
res=info.move(textInfos.UNIT_LINE,-1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_LINE,-1)
if res==0:
# Translators: a message reported when review cursor is at the top line of the current navigator object.
ui.reviewMessage(_("Top"))
Expand Down Expand Up @@ -1019,7 +1032,7 @@ def script_review_nextLine(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_LINE)
info.collapse()
res=info.move(textInfos.UNIT_LINE,1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_LINE,1)
if res==0:
# Translators: a message reported when review cursor is at the bottom line of the current navigator object.
ui.reviewMessage(_("Bottom"))
Expand All @@ -1033,7 +1046,9 @@ def script_review_nextLine(self,gesture):
script_review_nextLine.category=SCRCAT_TEXTREVIEW

def script_review_bottom(self,gesture):
info=api.getReviewPosition().obj.makeTextInfo(textInfos.POSITION_LAST)
obj = api.getReviewPosition().obj
pos = textInfos.POSITION_LASTVISIBLE if obj.reviewBounded else textInfos.POSITION_LAST
info = obj.makeTextInfo(pos)
api.setReviewPosition(info)
info.expand(textInfos.UNIT_LINE)
ui.reviewMessage(_("Bottom"))
Expand All @@ -1047,7 +1062,7 @@ def script_review_previousWord(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_WORD)
info.collapse()
res=info.move(textInfos.UNIT_WORD,-1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_WORD,-1)
if res==0:
# Translators: a message reported when review cursor is at the top line of the current navigator object.
ui.reviewMessage(_("Top"))
Expand Down Expand Up @@ -1078,7 +1093,7 @@ def script_review_nextWord(self,gesture):
if info._expandCollapseBeforeReview:
info.expand(textInfos.UNIT_WORD)
info.collapse()
res=info.move(textInfos.UNIT_WORD,1)
info, res = self._moveWithBoundsChecking(info, textInfos.UNIT_WORD,1)
if res==0:
# Translators: a message reported when review cursor is at the bottom line of the current navigator object.
ui.reviewMessage(_("Bottom"))
Expand Down
15 changes: 13 additions & 2 deletions source/textInfos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2006-2018 NV Access Limited, Babbage B.V.
#Copyright (C) 2006-2019 NV Access Limited, Babbage B.V., Bill Dengler

"""Framework for accessing text content in widgets.
The core component of this framework is the L{TextInfo} class.
Expand Down Expand Up @@ -155,6 +155,8 @@ def __repr__(self):
#Position constants
POSITION_FIRST="first"
POSITION_LAST="last"
POSITION_FIRSTVISIBLE="firstVisible"
POSITION_LASTVISIBLE="lastVisible"
POSITION_CARET="caret"
POSITION_SELECTION="selection"
POSITION_ALL="all"
Expand Down Expand Up @@ -259,7 +261,7 @@ class TextInfo(baseObject.AutoPropertyObject):
L{Points} must be supported as a position.
To support routing to a screen point from a given position, L{pointAtStart} or L{boundingRects} must be implemented.
In order to support text formatting or control information, L{getTextWithFields} should be overridden.

To support review bounds configuration, implement the L{isOutOfBounds} method and L{POSITION_FIRSTVISIBLE} and L{POSITION_LASTVISIBLE} positions.
@ivar bookmark: A unique identifier that can be used to make another textInfo object at this position.
@type bookmark: L{Bookmark}
"""
Expand Down Expand Up @@ -551,6 +553,15 @@ def getMathMl(self, field):
"""
raise NotImplementedError

def isOutOfBounds(self):
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns True if this textInfo is positioned outside its object's
Copy link
Contributor

Choose a reason for hiding this comment

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

If the text is partially visible, what is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on the underlying implementation.

visible text.
@rtype: bool
"""
raise NotImplementedError


RE_EOL = re.compile("\r\n|[\n\r]")
def convertToCrlf(text):
"""Convert a string so that it contains only CRLF line endings.
Expand Down
12 changes: 12 additions & 0 deletions source/textInfos/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ def __init__(self,obj,position):
self._startOffset=self._endOffset=0
elif position==textInfos.POSITION_LAST:
self._startOffset=self._endOffset=max(self._getStoryLength()-1,0)
elif position==textInfos.POSITION_FIRSTVISIBLE:
self._startOffset=self._endOffset=self._getFirstVisibleOffset()
elif position==textInfos.POSITION_LASTVISIBLE:
self._startOffset=self._endOffset=self._getLastVisibleOffset()
elif position==textInfos.POSITION_CARET:
self._startOffset=self._endOffset=self._getCaretOffset()
elif position==textInfos.POSITION_SELECTION:
Expand Down Expand Up @@ -457,6 +461,14 @@ def collapse(self,end=False):
def expand(self,unit):
self._startOffset,self._endOffset=self._getUnitOffsets(unit,self._startOffset)

def isOutOfBounds(self):
codeofdusk marked this conversation as resolved.
Show resolved Hide resolved
try:
return self._startOffset < self._getFirstVisibleOffset(
) or self._endOffset > self._getLastVisibleOffset()
except AttributeError, LookupError:
# Some implementations have incomplete support.
raise NotImplementedError

def copy(self):
return self.__class__(self.obj,self)

Expand Down
1 change: 1 addition & 0 deletions user_docs/en/userGuide.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ The following commands are available for reviewing text:
| Select then Copy to review cursor | NVDA+f10 | NVDA+f10 | none | On the first press, text is selected from the position previously set start marker up to and including the review cursor's current position. After pressing this key a second time, the text will be copied to the Windows clipboard |
| Report text formatting | NVDA+f | NVDA+f | none | Reports the formatting of the text where the review cursor is currently situated. Pressing twice shows the information in browse mode |
| Report current symbol replacement | None | None | none | Speaks the symbol where the review cursor is positioned. Pressed twice, shows the symbol and the text used to speak it in browse mode. |
| Toggle review bounds | NVDA+o | NVDA+o | none | Toggles whether the review cursor is constrained to the currently visible text. This is particularly useful in the Windows Console for reviewing text that has scrolled off the screen. |
%kc:endInclude

Note: numpad keys require numlock key to be turned off to work properly.
Expand Down