Skip to content

Commit

Permalink
Avoid full caret move timeout when pressing the delete key by treatin…
Browse files Browse the repository at this point in the history
…g valueChange events as caret moves. Also, treat caret events as caret moves as well, as this should be more reliable than comparing bookmarks in some cases.
  • Loading branch information
jcsteh committed Jun 21, 2017
1 parent 5da54fe commit c967b21
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions source/editableText.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,37 @@ def _hasCaretMoved(self, bookmark, retryInterval=0.01, timeout=None):
return (False,None)
api.processPendingEvents(processEventQueue=False)
if eventHandler.isPendingEvents("gainFocus"):
log.debug("Focus event. Elapsed: %d ms" % elapsed)
return (True,None)
#The caret may stop working as the focus jumps, we want to stay in the while loop though
# If the focus changes after this point, fetching the caret may fail,
# but we still want to stay in this loop.
try:
newInfo = self.makeTextInfo(textInfos.POSITION_CARET)
newBookmark = newInfo.bookmark
except (RuntimeError,NotImplementedError):
newInfo=None
else:
if newBookmark!=bookmark:
log.debug("Caret moved. Elapsed: %d ms" % elapsed)
return (True,newInfo)
newInfo = None
if eventHandler.isPendingEvents("caret"):
log.debug("caret event. Elapsed: %d ms" % elapsed)
return (True, newInfo)
if eventHandler.isPendingEvents("valueChange"):
# When pressing delete, the caret might not physically move,
# so the control might not fire a caret event,
# even though the text under the caret changes.
# We still want to treat this as a caret move.
# Otherwise, the user will have to wait
# the full timeout for feedback after pressing delete.
log.debug("valueChange event. Elapsed: %d ms" % elapsed)
return (True, newInfo)
# Some controls don't fire caret events.
# Try to detect with bookmarks.
newBookmark = None
if newInfo:
try:
newBookmark = newInfo.bookmark
except (RuntimeError,NotImplementedError):
pass
if newBookmark and newBookmark!=bookmark:
log.debug("Caret move detected using bookmarks. Elapsed: %d ms" % elapsed)
return (True, newInfo)
if elapsed >= timeoutMs:
break
time.sleep(retryInterval)
Expand Down

0 comments on commit c967b21

Please sign in to comment.