Skip to content

Commit

Permalink
Remove the isTyping logic from UIA consoles.
Browse files Browse the repository at this point in the history
This makes autoread work with more console programs at the cost of a few typed characters possibly being echoed/doubled.
  • Loading branch information
codeofdusk committed Jun 5, 2019
1 parent 4ff3172 commit 264697c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 28 additions & 14 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,25 @@ def __init__(self, obj, position, _rangeObj=None):
class winConsoleUIA(Terminal):
STABILIZE_DELAY = 0.03
_TextInfo = consoleUIATextInfo
_isTyping = False
_lastCharTime = 0
_queuedChars = []
_TYPING_TIMEOUT = 1
_hasNewLines = False

def _reportNewText(self, line):
# Additional typed character filtering beyond that in LiveText
if (
self._isTyping
and time.time() - self._lastCharTime <= self._TYPING_TIMEOUT
):
if len(line.strip()) < 3:
return
if self._hasNewLines:
# Clear the typed word buffer for new text lines.
# This will need to be changed once #8110 is merged.
speech.curWordChars = []
self._queuedChars = []
super(winConsoleUIA, self)._reportNewText(line)

def event_typedCharacter(self, ch):
if not ch.isspace():
self._isTyping = True
if ch in ('\n', '\r', '\t'):
# Clear the typed word buffer for tab and return.
if ch == '\t':
# Clear the typed word buffer for tab completion.
# This will need to be changed once #8110 is merged.
speech.curWordChars = []
self._lastCharTime = time.time()
if (
(
config.conf['keyboard']['speakTypedCharacters']
Expand All @@ -83,9 +80,12 @@ def event_textChange(self):
"kb:control+d",
"kb:control+pause"
])
def script_clear_isTyping(self, gesture):
def script_flush_queuedChars(self, gesture):
"""
Flushes the queue of typedCharacter events if present.
This is necessary to avoid speaking of passwords in the console if disabled.
"""
gesture.send()
self._isTyping = False
self._queuedChars = []

def _getTextLines(self):
Expand All @@ -94,3 +94,17 @@ def _getTextLines(self):
ptr = self.UIATextPattern.GetVisibleRanges()
res = [ptr.GetElement(i).GetText(-1) for i in range(ptr.length)]
return res

def _calculateNewText(self, newLines, oldLines):
self._hasNewLines = (
self._findLastLineIndex(newLines)
!= self._findLastLineIndex(oldLines)
)
return super(winConsoleUIA, self)._calculateNewText(newLines, oldLines)

def _findLastLineIndex(self, lines):
res = 0
for index, line in enumerate(lines):
if line:
res = index
return res
2 changes: 1 addition & 1 deletion source/NVDAObjects/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _monitor(self):
newLines = self._getTextLines()
if config.conf["presentation"]["reportDynamicContentChanges"]:
outLines = self._calculateNewText(newLines, oldLines)
if len(outLines) == 1 and len(outLines[0]) == 1:
if len(outLines) == 1 and len(outLines[0].strip()) == 1:
# This is only a single character,
# which probably means it is just a typed character,
# so ignore it.
Expand Down

0 comments on commit 264697c

Please sign in to comment.