From 1979d60f224453d9508e55d82a7ccb590a3a2912 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 14 Apr 2017 13:37:24 +0100 Subject: 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. --- lib/dom_utils.coffee | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'lib/dom_utils.coffee') 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. -- cgit v1.2.3