diff options
Diffstat (limited to 'content_scripts/scroller.coffee')
| -rw-r--r-- | content_scripts/scroller.coffee | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee index 3a1b3772..a533c161 100644 --- a/content_scripts/scroller.coffee +++ b/content_scripts/scroller.coffee @@ -128,13 +128,15 @@ checkVisibility = (element) -> CoreScroller = init: -> @time = 0 - @lastEvent = null - @keyIsDown = false + @lastEvent = @keyIsDown = @cancelEventListenerId = null + # This installs listeners for events which should cancel smooth scrolling. + installCanceEventListener: -> + @removeCancelEventListener() # NOTE(smblott) With extreme keyboard configurations, Chrome sometimes does not get a keyup event for # every keydown, in which case tapping "j" scrolls indefinitely. This appears to be a Chrome/OS/XOrg bug # of some kind. See #1549. - handlerStack.push + @cancelEventListenerId = handlerStack.push _name: 'scroller/track-key-status' keydown: (event) => handlerStack.alwaysContinueBubbling => @@ -149,6 +151,10 @@ CoreScroller = handlerStack.alwaysContinueBubbling => @time += 1 if event.target == window + removeCancelEventListener: -> + handlerStack.remove @cancelEventListenerId if @cancelEventListenerId? + @cancelEventListenerId = @lastEvent = @keyIsDown = null + # Return true if CoreScroller would not initiate a new scroll right now. wouldNotInitiateScroll: -> @lastEvent?.repeat and Settings.get "smoothScroll" @@ -175,7 +181,7 @@ CoreScroller = return if @lastEvent?.repeat activationTime = ++@time - myKeyIsStillDown = => @time == activationTime and @keyIsDown + myKeyIsStillDown = => @time == activationTime and @keyIsDown ? true # Store amount's sign and make amount positive; the arithmetic is clearer when amount is positive. sign = getSign amount @@ -215,13 +221,15 @@ CoreScroller = requestAnimationFrame animate else # We're done. + @removeCancelEventListener() checkVisibility element # If we've been asked not to be continuous, then we advance time, so the myKeyIsStillDown test always # fails. ++@time unless continuous - # Launch animator. + # Start scrolling. + @installCanceEventListener() requestAnimationFrame animate # Scroller contains the two main scroll functions which are used by clients. |
