Skip to content

Commit

Permalink
Make POSITION_FIRST and POSITION_LAST relative to visible text in FOR…
Browse files Browse the repository at this point in the history
…MATTED consoles.

The ability for users to explore all console text enabled by nvaccess#12669 has been well appreciated, but it poses problems in paginated output (less, more, etc.) as the review cursor jump to top/bottom commands are relative to the entire buffer, which can grow quite large. To ease review of paginated output, make these commands jump relative to visible (not full) text. Note that it is now impossible to jump quickly to the top/bottom of the entire buffer.
Closes nvaccess#13157.
  • Loading branch information
codeofdusk committed May 8, 2022
1 parent f90caa9 commit 819550a
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@


class ConsoleUIATextInfo(UIATextInfo):
"A TextInfo implementation for consoles with an IMPROVED, but not FORMATTED, API level."
"A TextInfo implementation for consoles with a FORMATTED API level."

# #13157: In FORMATTED consoles, the review cursor is not bounded to the
# visible text, allowing text to be freely explored.
# However, it is often useful to jump to the top or bottom of a screen of
# text when viewing paginated output. To enable this use case, make
# POSITION_FIRST and POSITION_LAST relative to the visible text.
_RESTRICT_TO_VISIBLE_POSITIONS = (
textInfos.POSITION_FIRST,
textInfos.POSITION_LAST
)

def __init__(self, obj, position, _rangeObj=None):
collapseToEnd = None
# We want to limit textInfos to just the visible part of the console.
# Therefore we specifically handle POSITION_FIRST, POSITION_LAST and POSITION_ALL.
if not _rangeObj and position in (
textInfos.POSITION_FIRST,
textInfos.POSITION_LAST,
textInfos.POSITION_ALL
):
if not _rangeObj and position in self._RESTRICT_TO_VISIBLE_POSITIONS:
try:
_rangeObj, collapseToEnd = self._getBoundingRange(obj, position)
except (COMError, RuntimeError):
Expand Down Expand Up @@ -61,6 +66,20 @@ def _getBoundingRange(self, obj, position):
collapseToEnd = True
return (_rangeObj, collapseToEnd)


class ConsoleUIATextInfoBounded(ConsoleUIATextInfo):
"A TextInfo implementation for consoles with an IMPROVED, but not FORMATTED, API level."

# Since pre-FORMATTED consoles have thousands of empty lines at the end of
# output, we want to limit textInfos to just the visible part of the
# console. Therefore we specifically handle POSITION_FIRST, POSITION_LAST
# and POSITION_ALL.
_RESTRICT_TO_VISIBLE_POSITIONS = (
textInfos.POSITION_FIRST,
textInfos.POSITION_LAST,
textInfos.POSITION_ALL
)

def move(self, unit, direction, endPoint=None):
oldInfo = None
if self.basePosition != textInfos.POSITION_CARET:
Expand Down Expand Up @@ -369,9 +388,9 @@ def _get_TextInfo(self):
ConsoleUIATextInfoWorkaroundEndInclusive fixes expand/collapse and implements
word movement."""
if self.apiLevel >= WinConsoleAPILevel.FORMATTED:
return UIATextInfo # No TextInfo workarounds needed
elif self.apiLevel >= WinConsoleAPILevel.IMPROVED:
return ConsoleUIATextInfo
elif self.apiLevel >= WinConsoleAPILevel.IMPROVED:
return ConsoleUIATextInfoBounded
else:
return ConsoleUIATextInfoWorkaroundEndInclusive

Expand Down Expand Up @@ -420,6 +439,9 @@ def findExtraOverlayClasses(obj, clsList):


class WinTerminalUIA(EnhancedTermTypedCharSupport):
def _get_TextInfo(self):
return ConsoleUIATextInfo

def event_UIA_notification(self, **kwargs):
"""
In an upcoming terminal release, UIA notification events will be sent
Expand Down

0 comments on commit 819550a

Please sign in to comment.