From 9fbd6b49015eba744dc2294642d96c481194930d Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Mon, 22 Jul 2019 14:06:11 +0800 Subject: [PATCH 01/11] Backport _getTextLines from #9735. --- source/NVDAObjects/UIA/winConsoleUIA.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/NVDAObjects/UIA/winConsoleUIA.py b/source/NVDAObjects/UIA/winConsoleUIA.py index cae4c4f8417..a1038d7a2f7 100644 --- a/source/NVDAObjects/UIA/winConsoleUIA.py +++ b/source/NVDAObjects/UIA/winConsoleUIA.py @@ -292,9 +292,12 @@ def script_flush_queuedChars(self, gesture): def _getTextLines(self): # Filter out extraneous empty lines from UIA - ptr = self.UIATextPattern.GetVisibleRanges() - res = [ptr.GetElement(i).GetText(-1) for i in range(ptr.length)] - return res + return ( + self.makeTextInfo(textInfos.POSITION_ALL) + ._rangeObj.getText(-1) + .rstrip() + .split("\r\n") + ) def _calculateNewText(self, newLines, oldLines): self._hasNewLines = ( From 90fe976ba4bf8f35ac1caaa6b8b554a5fd3e1d42 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Mon, 22 Jul 2019 14:18:18 +0800 Subject: [PATCH 02/11] Move the isOffscreen logic from #9735 to a function in UIAUtils and disable the console bounds checking code when oldRange is also offscreen. --- source/NVDAObjects/UIA/winConsoleUIA.py | 15 ++++++--------- source/UIAUtils.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/source/NVDAObjects/UIA/winConsoleUIA.py b/source/NVDAObjects/UIA/winConsoleUIA.py index a1038d7a2f7..82e35436f04 100644 --- a/source/NVDAObjects/UIA/winConsoleUIA.py +++ b/source/NVDAObjects/UIA/winConsoleUIA.py @@ -13,6 +13,7 @@ import UIAHandler from scriptHandler import script +from UIAUtils import isTextRangeOffscreen from winVersion import isWin10 from . import UIATextInfo from ..behaviors import Terminal @@ -50,8 +51,6 @@ def move(self, unit, direction, endPoint=None): 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. @@ -108,13 +107,11 @@ def move(self, unit, direction, endPoint=None): 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): + if ( + oldRange + and isTextRangeOffscreen(self._rangeObj, visiRanges) + and not isTextRangeOffscreen(oldRange, visiRanges) + ): self._rangeObj = oldRange return 0 return res diff --git a/source/UIAUtils.py b/source/UIAUtils.py index 7704b12aa2d..5acedf8cc4c 100644 --- a/source/UIAUtils.py +++ b/source/UIAUtils.py @@ -172,6 +172,24 @@ def getChildrenWithCacheFromUIATextRange(textRange,cacheRequest): c=CacheableUIAElementArray(c) return c +def isTextRangeOffscreen(range, visiRanges): + """Given a UIA text range and a visible ranges array (returned from obj.UIATextPattern.GetVisibleRanges), determines if the given range is not within the visible ranges.""" + visiLength = visiRanges.length + if visiLength > 0: + firstVisiRange = visiRanges.GetElement(0) + lastVisiRange = visiRanges.GetElement(visiLength - 1) + return range.CompareEndPoints( + UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange, + UIAHandler.TextPatternRangeEndpoint_Start + ) < 0 or range.CompareEndPoints( + UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange, + UIAHandler.TextPatternRangeEndpoint_End) >= 0 + else: + # Visible ranges not available, so fail gracefully. + log.warning("UIA visible ranges not available.") + return True + + class UIATextRangeAttributeValueFetcher(object): def __init__(self,textRange): From c5eee9106d5fc38de3781525257bedbb7372fe53 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Mon, 22 Jul 2019 14:36:21 +0800 Subject: [PATCH 03/11] Re-implement POSITION_FIRST and POSITION_LAST in terms of visible ranges to fix review top/bottom scripts. --- source/NVDAObjects/UIA/winConsoleUIA.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/NVDAObjects/UIA/winConsoleUIA.py b/source/NVDAObjects/UIA/winConsoleUIA.py index 82e35436f04..9171b283f02 100644 --- a/source/NVDAObjects/UIA/winConsoleUIA.py +++ b/source/NVDAObjects/UIA/winConsoleUIA.py @@ -27,6 +27,21 @@ class consoleUIATextInfo(UIATextInfo): #: to do much good either. _expandCollapseBeforeReview = False + def __init__(self,obj,position,_rangeObj=None): + super(consoleUIATextInfo, self).__init__(obj, position, _rangeObj) + # Re-implement POSITION_FIRST and POSITION_LAST in terms of + # visible ranges to fix review top/bottom scripts. + if position==textInfos.POSITION_FIRST: + visiRanges = self.obj.UIATextPattern.GetVisibleRanges() + firstVisiRange = visiRanges.GetElement(0) + self._rangeObj = firstVisiRange + self.collapse() + elif position==textInfos.POSITION_LAST: + visiRanges = self.obj.UIATextPattern.GetVisibleRanges() + lastVisiRange = visiRanges.GetElement(visiRanges.length - 1) + self._rangeObj = lastVisiRange + self.collapse(True) + def collapse(self,end=False): """Works around a UIA bug on Windows 10 1903 and later.""" if not isWin10(1903): From 78d59c1383d2d5faa32614d33eb3ad62743c5a88 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Mon, 22 Jul 2019 19:46:53 +0800 Subject: [PATCH 04/11] Review actions. --- source/NVDAObjects/UIA/winConsoleUIA.py | 19 +++++++++++-------- source/UIAUtils.py | 5 ++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/NVDAObjects/UIA/winConsoleUIA.py b/source/NVDAObjects/UIA/winConsoleUIA.py index 9171b283f02..a4b85a83a82 100644 --- a/source/NVDAObjects/UIA/winConsoleUIA.py +++ b/source/NVDAObjects/UIA/winConsoleUIA.py @@ -12,6 +12,7 @@ import textInfos import UIAHandler +from comtypes import COMError from scriptHandler import script from UIAUtils import isTextRangeOffscreen from winVersion import isWin10 @@ -108,7 +109,6 @@ def move(self, unit, direction, endPoint=None): lineInfo.expand(textInfos.UNIT_LINE) offset = self._getCurrentOffsetInThisLine(lineInfo) # Finally using the new offset, - # Calculate the current word offsets and move to the start of # this word if we are not already there. start, end = self._getWordOffsetsInThisLine(offset, lineInfo) @@ -122,13 +122,16 @@ def move(self, unit, direction, endPoint=None): else: # moving by a unit other than word res = super(consoleUIATextInfo, self).move(unit, direction, endPoint) - if ( - oldRange - and isTextRangeOffscreen(self._rangeObj, visiRanges) - and not isTextRangeOffscreen(oldRange, visiRanges) - ): - self._rangeObj = oldRange - return 0 + try: + if ( + oldRange + and isTextRangeOffscreen(self._rangeObj, visiRanges) + and not isTextRangeOffscreen(oldRange, visiRanges) + ): + self._rangeObj = oldRange + return 0 + except COMError, RuntimeError: + pass return res def expand(self, unit): diff --git a/source/UIAUtils.py b/source/UIAUtils.py index 5acedf8cc4c..1baf2e7131b 100644 --- a/source/UIAUtils.py +++ b/source/UIAUtils.py @@ -185,9 +185,8 @@ def isTextRangeOffscreen(range, visiRanges): UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange, UIAHandler.TextPatternRangeEndpoint_End) >= 0 else: - # Visible ranges not available, so fail gracefully. - log.warning("UIA visible ranges not available.") - return True + # Visible ranges not available. + raise RuntimeError("Visible ranges array is empty or invalid.") class UIATextRangeAttributeValueFetcher(object): From 00d37459f2236af5a82f3dff813f60e861ba3cf0 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Sat, 27 Jul 2019 09:12:42 -0400 Subject: [PATCH 05/11] range -> textRange. --- source/UIAUtils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/UIAUtils.py b/source/UIAUtils.py index 1baf2e7131b..20284c0e648 100644 --- a/source/UIAUtils.py +++ b/source/UIAUtils.py @@ -172,21 +172,21 @@ def getChildrenWithCacheFromUIATextRange(textRange,cacheRequest): c=CacheableUIAElementArray(c) return c -def isTextRangeOffscreen(range, visiRanges): - """Given a UIA text range and a visible ranges array (returned from obj.UIATextPattern.GetVisibleRanges), determines if the given range is not within the visible ranges.""" +def isTextRangeOffscreen(textRange, visiRanges): + """Given a UIA text range and a visible textRanges array (returned from obj.UIATextPattern.GetVisibleRanges), determines if the given textRange is not within the visible textRanges.""" visiLength = visiRanges.length if visiLength > 0: firstVisiRange = visiRanges.GetElement(0) lastVisiRange = visiRanges.GetElement(visiLength - 1) - return range.CompareEndPoints( + return textRange.CompareEndPoints( UIAHandler.TextPatternRangeEndpoint_Start, firstVisiRange, UIAHandler.TextPatternRangeEndpoint_Start - ) < 0 or range.CompareEndPoints( + ) < 0 or textRange.CompareEndPoints( UIAHandler.TextPatternRangeEndpoint_Start, lastVisiRange, UIAHandler.TextPatternRangeEndpoint_End) >= 0 else: - # Visible ranges not available. - raise RuntimeError("Visible ranges array is empty or invalid.") + # Visible textRanges not available. + raise RuntimeError("Visible textRanges array is empty or invalid.") class UIATextRangeAttributeValueFetcher(object): From 0ed4c34baae86181cf1fe229f58928b7aafd1392 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Sat, 27 Jul 2019 12:26:28 -0400 Subject: [PATCH 06/11] Add parentheses for Python 3. --- source/NVDAObjects/UIA/winConsoleUIA.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/NVDAObjects/UIA/winConsoleUIA.py b/source/NVDAObjects/UIA/winConsoleUIA.py index b09bc71d754..edec5ba1a2b 100644 --- a/source/NVDAObjects/UIA/winConsoleUIA.py +++ b/source/NVDAObjects/UIA/winConsoleUIA.py @@ -130,7 +130,7 @@ def move(self, unit, direction, endPoint=None): ): self._rangeObj = oldRange return 0 - except COMError, RuntimeError: + except (COMError, RuntimeError): pass return res From 0241799350cf950f5afc18e2bed09189dd7729fa Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Tue, 30 Jul 2019 08:49:48 -0400 Subject: [PATCH 07/11] Update user guide. --- user_docs/en/userGuide.t2t | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/user_docs/en/userGuide.t2t b/user_docs/en/userGuide.t2t index 42c0e6e94c5..1732a54e343 100644 --- a/user_docs/en/userGuide.t2t +++ b/user_docs/en/userGuide.t2t @@ -942,6 +942,16 @@ When in the table view of added books: | Context menu | applications | Opens the context menu for the selected book. | %kc:endInclude +++ Windows Console ++[WinConsole] +NVDA provides support for the Windows command console used by Command Prompt, PowerShell, and the Windows Subsystem for Linux. +%kc:beginInclude +The following Windows Console keyboard shortcuts may be useful when [reviewing text #ReviewingText] with NVDA: +|| Name | Key | Description | +| Scroll up | control+upArrow | Scrolls the console screen up, so earlier text can be read. | +| Scroll down | control+downArrow | Scrolls the console screen down, so later text can be read. | +| Scroll to end | control+end | Scrolls the console screen to the end of the buffer. | +%kc:endInclude + + Configuring NVDA +[ConfiguringNVDA] Most configuration can be performed using dialog boxes accessed through the Preferences sub-menu of the NVDA menu. Many of these settings can be found in the multi-page [NVDA Settings dialog #NVDASettings]. From 984bea103d741e2556cf4c923f5b5a1d9c00d024 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Wed, 31 Jul 2019 04:13:53 -0400 Subject: [PATCH 08/11] Update user guide. --- user_docs/en/userGuide.t2t | 1 + 1 file changed, 1 insertion(+) diff --git a/user_docs/en/userGuide.t2t b/user_docs/en/userGuide.t2t index 1732a54e343..ea091fa94b0 100644 --- a/user_docs/en/userGuide.t2t +++ b/user_docs/en/userGuide.t2t @@ -949,6 +949,7 @@ The following Windows Console keyboard shortcuts may be useful when [reviewing t || Name | Key | Description | | Scroll up | control+upArrow | Scrolls the console screen up, so earlier text can be read. | | Scroll down | control+downArrow | Scrolls the console screen down, so later text can be read. | +| Scroll to start | control+home | Scrolls the console screen to the beginning of the buffer. | | Scroll to end | control+end | Scrolls the console screen to the end of the buffer. | %kc:endInclude From dadb1b0d0456f6887416af52a35b576cd5b01007 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Thu, 1 Aug 2019 05:33:53 -0400 Subject: [PATCH 09/11] Update user guide. --- user_docs/en/userGuide.t2t | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/user_docs/en/userGuide.t2t b/user_docs/en/userGuide.t2t index ea091fa94b0..de7895dfa37 100644 --- a/user_docs/en/userGuide.t2t +++ b/user_docs/en/userGuide.t2t @@ -944,13 +944,15 @@ When in the table view of added books: ++ Windows Console ++[WinConsole] NVDA provides support for the Windows command console used by Command Prompt, PowerShell, and the Windows Subsystem for Linux. +The console window is of fixed size: as new text is written, previous text is removed to make space. +Therefore, it is necessary to scroll the console window to read earlier text. %kc:beginInclude -The following Windows Console keyboard shortcuts may be useful when [reviewing text #ReviewingText] with NVDA: +The following built-in Windows Console keyboard shortcuts may be useful when [reviewing text #ReviewingText] with NVDA: || Name | Key | Description | -| Scroll up | control+upArrow | Scrolls the console screen up, so earlier text can be read. | -| Scroll down | control+downArrow | Scrolls the console screen down, so later text can be read. | -| Scroll to start | control+home | Scrolls the console screen to the beginning of the buffer. | -| Scroll to end | control+end | Scrolls the console screen to the end of the buffer. | +| Scroll up | control+upArrow | Scrolls the console window up, so earlier text can be read. | +| Scroll down | control+downArrow | Scrolls the console window down, so later text can be read. | +| Scroll to start | control+home | Scrolls the console window to the beginning of the text. | +| Scroll to end | control+end | Scrolls the console window to the end of the text. | %kc:endInclude + Configuring NVDA +[ConfiguringNVDA] From 532a71a418cf1953c3c5078c8eeda8c492918762 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Thu, 1 Aug 2019 10:58:55 -0400 Subject: [PATCH 10/11] Update user_docs/en/userGuide.t2t Co-Authored-By: Reef Turner --- user_docs/en/userGuide.t2t | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_docs/en/userGuide.t2t b/user_docs/en/userGuide.t2t index de7895dfa37..517b98d55b1 100644 --- a/user_docs/en/userGuide.t2t +++ b/user_docs/en/userGuide.t2t @@ -944,7 +944,9 @@ When in the table view of added books: ++ Windows Console ++[WinConsole] NVDA provides support for the Windows command console used by Command Prompt, PowerShell, and the Windows Subsystem for Linux. -The console window is of fixed size: as new text is written, previous text is removed to make space. +The console window is of fixed size, typically much smaller than the buffer that holds the output. +As new text is written, the content scroll upwards and previous text is no longer visible. +Text that is not visibly displayed in the window is not accessible with NVDA's text review commands. Therefore, it is necessary to scroll the console window to read earlier text. %kc:beginInclude The following built-in Windows Console keyboard shortcuts may be useful when [reviewing text #ReviewingText] with NVDA: From f4bfd26c295c51cd2cb9452761764d586cfa6cc4 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Thu, 1 Aug 2019 11:01:08 -0400 Subject: [PATCH 11/11] Update user guide. --- user_docs/en/userGuide.t2t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/user_docs/en/userGuide.t2t b/user_docs/en/userGuide.t2t index 865a860bac9..afed9c7cc78 100644 --- a/user_docs/en/userGuide.t2t +++ b/user_docs/en/userGuide.t2t @@ -953,8 +953,8 @@ The following built-in Windows Console keyboard shortcuts may be useful when [re || Name | Key | Description | | Scroll up | control+upArrow | Scrolls the console window up, so earlier text can be read. | | Scroll down | control+downArrow | Scrolls the console window down, so later text can be read. | -| Scroll to start | control+home | Scrolls the console window to the beginning of the text. | -| Scroll to end | control+end | Scrolls the console window to the end of the text. | +| Scroll to start | control+home | Scrolls the console window to the beginning of the buffer. | +| Scroll to end | control+end | Scrolls the console window to the end of the buffer. | %kc:endInclude + Configuring NVDA +[ConfiguringNVDA]