Skip to content

Commit

Permalink
editableText.EditableText._hasCaretMoved: only fall back to checking …
Browse files Browse the repository at this point in the history
…if the word at the caret has changed once _hasCaretMoved_minWordTimeoutMs has elapsed. I.e. 30 ms must elapse before starting to check the word. (#7496)

This fixes a regression introduced by #7201 where deleting characters in Mozilla Gecko editable controls would cause the character being deleted to be spoken rather than the character that followed.
  • Loading branch information
michaelDCurran authored Aug 15, 2017
1 parent ffa71c7 commit baee68d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/editableText.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class EditableText(ScriptableObject):
#: Whether or not to announce text found before the caret on a new line (e.g. auto numbering)
announceNewLineText=True

_hasCaretMoved_minWordTimeoutMs=30 #: The minimum amount of time that should elapse before checking if the word under the caret has changed

def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=None):
"""
Waits for the caret to move, for a timeout to elapse, or for a new focus event or script to be queued.
Expand Down Expand Up @@ -93,8 +95,11 @@ def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None, origWord=No
if newBookmark and newBookmark!=bookmark:
log.debug("Caret move detected using bookmarks. Elapsed: %d ms" % elapsed)
return (True, newInfo)
if origWord is not None and newInfo:
if origWord is not None and newInfo and elapsed >= self._hasCaretMoved_minWordTimeoutMs:
# When pressing delete, bookmarks might not be enough to detect caret movement.
# Therefore try detecting if the word under the caret has changed, such as when pressing delete.
# some editors such as Mozilla Gecko can have text and units that get out of sync with eachother while a character is being deleted.
# Therefore, only check if the word has changed after a particular amount of time has elapsed, allowing the text and units to settle down.
wordInfo = newInfo.copy()
wordInfo.expand(textInfos.UNIT_WORD)
word = wordInfo.text
Expand Down

0 comments on commit baee68d

Please sign in to comment.