From eb2eb7c4368108fcd0e1472f6ef34ca2416b5371 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 28 Feb 2016 12:14:14 +0000 Subject: Fix for F. We were immediately restarting link-hints mode if a count was present. Unfortunately, that meant that we were detecting our own link-hint click and exiting immediately. So, with a count of 6, we were only getting 3 link-hint activations. To avoid this, we add a short delay (just nextTick). Also, move some other stuff arund to make sure this works in all cases (e.g. wait-for-enter). --- content_scripts/link_hints.coffee | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 8d75ed32..c8f9b6f9 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -26,7 +26,9 @@ LinkHints = # can exit following which we do not restart hints mode. return if event?.type == "keydown" and KeyboardUtils.isEscape event return if event?.type == "keydown" and event.keyCode in [ keyCodes.backspace, keyCodes.deleteKey ] - LinkHints.activateMode count-1, mode + # Wait for the next tick to allow the previous mode to exit. It might yet generate a click event, + # which would cause our new mode to exit immediately. + Utils.nextTick -> LinkHints.activateMode count-1, mode activateModeToOpenInNewTab: (count) -> @activateMode count, OPEN_IN_NEW_BG_TAB activateModeToOpenInNewForegroundTab: (count) -> @activateMode count, OPEN_IN_NEW_FG_TAB @@ -389,11 +391,10 @@ class LinkHintsMode @linkActivator(clickEl) LinkHints.activateModeWithQueue() if @mode is OPEN_WITH_QUEUE - delay = 0 if waitForEnter - @deactivateMode delay, => - if waitForEnter - new WaitForEnter @matchedLink.rect, linkActivator - else + if waitForEnter + new WaitForEnter @matchedLink.rect, => @deactivateMode 0, linkActivator + else + @deactivateMode delay, => DomUtils.flashRect @matchedLink.rect linkActivator() @@ -421,18 +422,16 @@ class LinkHintsMode @onExit?() @onExit = null @tabCount = 0 + callback?() if delay # Install a mode to block keyboard events if the user is still typing. The intention is to prevent the # user from inadvertently launching Vimium commands when typing the link text. - new TypingProtector delay, @matchedLink?.rect, -> - deactivate() - callback?() + new TypingProtector delay, @matchedLink?.rect, deactivate else # We invoke deactivate() directly (instead of setting a timeout of 0) so that deactivateMode() can be # tested synchronously. deactivate() - callback?() # Use characters for hints, and do not filter links by their text. class AlphabetHints -- cgit v1.2.3