Skip to content

Commit

Permalink
Optimization: clear character buffers when reporting new lines.
Browse files Browse the repository at this point in the history
This saves us from scanning the old and new lines twice in _calculateNewText (once for diffing and once for finding nonblank indices), and fixes typed word reporting for 21H1 console.

This new approach does not resolve nvaccess#10942.
  • Loading branch information
codeofdusk committed Apr 5, 2020
1 parent 6ff9867 commit a563791
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions source/NVDAObjects/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ def _reportNewLines(self, lines):
and len(lines[0].strip()) < max(len(speech.curWordChars) + 1, 3)
):
return
# Clear the typed word buffer for new text lines.
speech.clearTypedWordBuffer()
self._queuedChars = []
super()._reportNewLines(lines)

def event_typedCharacter(self, ch):
Expand Down Expand Up @@ -459,30 +462,13 @@ def script_flush_queuedChars(self, gesture):
speech.clearTypedWordBuffer()
gesture.send()

def _calculateNewText(self, newLines, oldLines):
hasNewLines = (
self._findNonBlankIndices(newLines)
!= self._findNonBlankIndices(oldLines)
)
if hasNewLines:
# Clear the typed word buffer for new text lines.
speech.clearTypedWordBuffer()
self._queuedChars = []
return super()._calculateNewText(newLines, oldLines)

def _dispatchQueue(self):
"""Sends queued typedCharacter events through to NVDA."""
while self._queuedChars:
ch = self._queuedChars.pop(0)
super().event_typedCharacter(ch)

def _findNonBlankIndices(self, lines):
"""
Given a list of strings, returns a list of indices where the strings
are not empty.
"""
return [index for index, line in enumerate(lines) if line]


class KeyboardHandlerBasedTypedCharSupport(EnhancedTermTypedCharSupport):
"""An EnhancedTermTypedCharSupport object that provides typed character support for
Expand Down

0 comments on commit a563791

Please sign in to comment.