aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/scroller.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-12-21 05:09:42 +0000
committerGitHub2016-12-21 05:09:42 +0000
commit320f433afb53cc774b175dab0f6a1ad7a47d60f9 (patch)
tree2bb28d6c6afc7ceeb7f463c6aff23d201b43587b /content_scripts/scroller.coffee
parentcaa63d6642141d2fe4cd6941ec1e84dd2d3e8225 (diff)
parentedfb7ba3ca148f7b00bd683d1979330f395f2e7e (diff)
downloadvimium-320f433afb53cc774b175dab0f6a1ad7a47d60f9.tar.bz2
Merge pull request #2311 from smblott-github/enterNormalMode
New command option to enter normal mode
Diffstat (limited to 'content_scripts/scroller.coffee')
-rw-r--r--content_scripts/scroller.coffee18
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.