diff options
Diffstat (limited to 'content_scripts/link_hints.coffee')
| -rw-r--r-- | content_scripts/link_hints.coffee | 27 | 
1 files changed, 21 insertions, 6 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index cdd2dfac..bf120629 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -34,8 +34,6 @@ class LinkHintsMode    mode: undefined    # Function that does the appropriate action on the selected link.    linkActivator: undefined -  # While in delayMode, all keypresses have no effect. -  delayMode: false    # Lock to ensure only one instance runs at a time.    isActive: false    # The link-hints "mode" (in the key-handler, indicator sense). @@ -287,7 +285,7 @@ class LinkHintsMode    # Handles <Shift> and <Ctrl>.    onKeyDownInMode: (hintMarkers, event) -> -    return if @delayMode or event.repeat +    return if event.repeat      @keydownKeyChar = KeyboardUtils.getKeyChar(event).toLowerCase()      previousTabCount = @tabCount @@ -334,7 +332,7 @@ class LinkHintsMode    # Handles normal input.    onKeyPressInMode: (hintMarkers, event) -> -    return if @delayMode or event.repeat +    return if event.repeat      keyChar = String.fromCharCode(event.charCode).toLowerCase()      if keyChar @@ -359,7 +357,6 @@ class LinkHintsMode    # When only one link hint remains, this function activates it in the appropriate way.    #    activateLink: (matchedLink, delay = 0) -> -    @delayMode = true      clickEl = matchedLink.clickableItem      if (DomUtils.isSelectable(clickEl))        DomUtils.simulateSelect(clickEl) @@ -401,7 +398,9 @@ class LinkHintsMode        @tabCount = 0      if delay -      Utils.setTimeout 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, ->          deactivate()          callback?()      else @@ -657,6 +656,22 @@ numberToHintString = (number, characterSet, numHintDigits = 0) ->    hintString.join("") +# Suppress all keyboard events until the user stops typing for sufficiently long. +class TypingProtector extends Mode +  constructor: (delay, callback) -> +    @timer = Utils.setTimeout delay, => @exit() + +    handler = (event) => +      clearTimeout @timer +      @timer = Utils.setTimeout 150, => @exit() + +    super +      name: "hint/typing-protector" +      suppressAllKeyboardEvents: true +      keydown: handler +      keypress: handler + +    @onExit callback  root = exports ? window  root.LinkHints = LinkHints  | 
