Skip to content

Commit

Permalink
winConsoleUIA: Greatly speed up move by word (#10522)
Browse files Browse the repository at this point in the history
* winConsoleUIATextInfo: greatly speed up moving by word by calculating current offset within a line by counting utf16 characters in the text rather than calling move with unit character over and over again.

* Fix linting issues.

* WinConsoleUIA: slightly refactor move by word to avoid unnecessary math.
  • Loading branch information
michaelDCurran authored Nov 21, 2019
1 parent 02f1dff commit 3cd482f
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions source/NVDAObjects/UIA/winConsoleUIA.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ctypes
import NVDAHelper
import textInfos
import textUtils
import UIAHandler

from comtypes import COMError
Expand Down Expand Up @@ -203,23 +204,12 @@ def _getCurrentOffsetInThisLine(self, lineInfo):
This is necessary since Uniscribe requires indices into the text to
find word boundaries, but UIA only allows for relative movement.
"""
charInfo = self.copy()
res = 0
chars = None
while charInfo.compareEndPoints(
lineInfo,
"startToEnd"
) <= 0:
charInfo.expand(textInfos.UNIT_CHARACTER)
chars = charInfo.move(textInfos.UNIT_CHARACTER, -1) * -1
if chars != 0 and charInfo.compareEndPoints(
lineInfo,
"startToStart"
) >= 0:
res += chars
else:
break
return res
# position a textInfo from the start of the line up to the current position.
charInfo = lineInfo.copy()
charInfo.setEndPoint(self, "endToStart")
text = charInfo.text
offset = textUtils.WideStringOffsetConverter(text).wideStringLength
return offset

def _getWordOffsetsInThisLine(self, offset, lineInfo):
lineText = lineInfo.text or u" "
Expand All @@ -232,16 +222,17 @@ def _getWordOffsetsInThisLine(self, offset, lineInfo):
# not more than two alphanumeric chars in a row.
# Inject two alphanumeric characters at the end to fix this.
lineText += "xx"
lineTextLen = textUtils.WideStringOffsetConverter(lineText).wideStringLength
NVDAHelper.localLib.calculateWordOffsets(
lineText,
len(lineText),
lineTextLen,
offset,
ctypes.byref(start),
ctypes.byref(end)
)
return (
start.value,
min(end.value, max(1, len(lineText) - 2))
min(end.value, max(1, lineTextLen - 2))
)

def __ne__(self, other):
Expand Down

0 comments on commit 3cd482f

Please sign in to comment.