diff options
| author | Stephen Blott | 2017-04-14 13:37:24 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2017-04-18 05:50:51 +0100 | 
| commit | 1979d60f224453d9508e55d82a7ccb590a3a2912 (patch) | |
| tree | bc999e4864903075b871031093a91325c8887db4 /lib/dom_utils.coffee | |
| parent | 17722aa93ba2f0fb08ee87dc76698fb37a2e0fd9 (diff) | |
| download | vimium-1979d60f224453d9508e55d82a7ccb590a3a2912.tar.bz2 | |
Make the consumeKeyup handler a singleton.
That is, allow at most one handler to be installed at any one time.
I have not observed this to be necessary.  However, if there were any
systematic way in which we weren't seeing the necessary keyup events,
then these handlers would just be added and added.  So this seems safer.
Diffstat (limited to 'lib/dom_utils.coffee')
| -rw-r--r-- | lib/dom_utils.coffee | 36 | 
1 files changed, 20 insertions, 16 deletions
| diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 3f0bd7f3..1864d973 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -305,22 +305,26 @@ DomUtils =      event.preventDefault()      @suppressPropagation(event) -  consumeKeyup: (event, callback = null) -> -    code = event.code -    unless event.repeat -      handlerStack.push -        _name: "dom_utils/consumeKeyup" -        keyup: (event) -> -          return handlerStack.continueBubbling unless event.code == code -          @remove() -          handlerStack.suppressEvent -        # We cannot track keyup events if we lose the focus. -        blur: (event) -> -          @remove() if event.target == window -          handlerStack.continueBubbling -    callback?() -    @suppressEvent event -    handlerStack.suppressEvent +  consumeKeyup: do -> +    handlerId = null + +    (event, callback = null) -> +      unless event.repeat +        handlerStack.remove handlerId ? "not-an-id" +        code = event.code +        handlerId = handlerStack.push +          _name: "dom_utils/consumeKeyup" +          keyup: (event) -> +            return handlerStack.continueBubbling unless event.code == code +            @remove() +            handlerStack.suppressEvent +          # We cannot track keyup events if we lose the focus. +          blur: (event) -> +            @remove() if event.target == window +            handlerStack.continueBubbling +      callback?() +      @suppressEvent event +      handlerStack.suppressEvent    # Adapted from: http://roysharon.com/blog/37.    # This finds the element containing the selection focus. | 
