From 90d1c82346550acfb6e87dcc05be642f9d4953b4 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 21 Jun 2019 17:16:36 -0400 Subject: [PATCH] Fix #9786. --- source/editableText.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/source/editableText.py b/source/editableText.py index db948ce88bc..2b59a2e863c 100755 --- a/source/editableText.py +++ b/source/editableText.py @@ -48,7 +48,11 @@ class EditableText(TextContainerObject,ScriptableObject): _hasCaretMoved_minWordTimeoutMs=30 #: The minimum amount of time that should elapse before checking if the word under the caret has changed - _caretMovementTimeoutMultiplier = 1 + #: The caret movement timeout is multiplied by this value (useful for + #: controls where the caret is slow to move). + #: Set to a number grater than 0 to enable caret event handling + #: (e.g. from UIA). + _caretMovementTimeoutMultiplier = 0 def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=None): """ @@ -71,7 +75,8 @@ def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=No else: # This function's arguments are in seconds, but we want ms. timeoutMs = timeout * 1000 - timeoutMs *= self._caretMovementTimeoutMultiplier + if self._caretMovementTimeoutMultiplier: + timeoutMs *= self._caretMovementTimeoutMultiplier # time.sleep accepts seconds, so retryInterval is in seconds. # Convert to integer ms to avoid floating point precision errors when adding to elapsed. retryMs = int(retryInterval * 1000) @@ -84,10 +89,11 @@ def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=No if eventHandler.isPendingEvents("gainFocus"): log.debug("Focus event. Elapsed: %d ms" % elapsed) return (True,None) - # Some controls implement a caret event - if eventHandler.isPendingEvents("caret"): - newInfo = self.makeTextInfo(textInfos.POSITION_CARET) - return (True, newInfo) + if self._caretMovementTimeoutMultiplier: + # Some controls implement a caret event + if eventHandler.isPendingEvents("caret"): + newInfo = self.makeTextInfo(textInfos.POSITION_CARET) + return (True, newInfo) # If the focus changes after this point, fetching the caret may fail, # but we still want to stay in this loop. try: