aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2014-11-11 18:54:23 +0000
committerStephen Blott2014-11-11 18:58:49 +0000
commit9ae1561caac47c8f4739492e66e3986f1977a3cb (patch)
treef872c8b10cc6676298736b68238a07777a8d206f /content_scripts
parent553a5c21aef68811d7e9289a68edea11613f93ea (diff)
downloadvimium-9ae1561caac47c8f4739492e66e3986f1977a3cb.tar.bz2
Smooth scroll; comments and more minor tidy up.
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/scroller.coffee28
-rw-r--r--content_scripts/vimium_frontend.coffee8
2 files changed, 19 insertions, 17 deletions
diff --git a/content_scripts/scroller.coffee b/content_scripts/scroller.coffee
index 683e7f99..33deb5cf 100644
--- a/content_scripts/scroller.coffee
+++ b/content_scripts/scroller.coffee
@@ -95,20 +95,24 @@ doScrollBy = do ->
lastEvent = null
keyHandler = null
- (element, direction, amount, wantSmooth) ->
- if not keyHandler
- keyHandler = root.handlerStack.push
+ (element, direction, amount) ->
+ return unless amount
+
+ unless keyHandler
+ keyHandler = handlerStack.push
keydown: (event) -> lastEvent = event
keyup: -> time += 1
axisName = scrollProperties[direction].axisName
- unless wantSmooth and settings.get "smoothScroll"
+ unless settings.get "smoothScroll"
return performScroll element, axisName, amount
if mostRecentActivationId == time or lastEvent?.repeat
# Either the most-recently activated animator has not yet received its keyup event (so it's still
- # scrolling), or this is a keyboard repeat (for which we don't initiate a new animator).
+ # scrolling), or this is a keyboard repeat (for which we don't initiate a new animator). We need both
+ # of these checks because sometimes (perhaps one time in twenty) the last keyboard repeat arrives
+ # *after* the corresponding keyup.
return
mostRecentActivationId = activationId = ++time
@@ -128,11 +132,9 @@ doScrollBy = do ->
scrolledAmount = 0
shouldStopScrolling = (progress) ->
- if activationId == time
- # This is the most recently-activated animator and we haven't yet seen its keyup event, so keep going.
- false
- else
- duration <= progress
+ # If activationId == time, then this is the most recently-activated animator and we haven't yet seen its
+ # keyup event, so keep going.
+ if activationId == time then false else duration <= progress
animate = (timestamp) ->
start ?= timestamp
@@ -171,15 +173,15 @@ Scroller =
element = findScrollableElement activatedElement, direction, amount, factor
elementAmount = factor * getDimension element, direction, amount
- doScrollBy element, direction, elementAmount, true
+ doScrollBy element, direction, elementAmount
- scrollTo: (direction, pos, wantSmooth = false) ->
+ scrollTo: (direction, pos) ->
return unless document.body or activatedElement
activatedElement ||= document.body
element = findScrollableElement activatedElement, direction, pos
amount = getDimension(element,direction,pos) - element[scrollProperties[direction].axisName]
- doScrollBy element, direction, amount, wantSmooth
+ doScrollBy element, direction, amount
root = exports ? window
root.Scroller = Scroller
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 57503565..9c59396f 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -227,10 +227,10 @@ window.focusThisFrame = (shouldHighlight) ->
setTimeout((-> document.body.style.border = borderWas), 200)
extend window,
- scrollToBottom: -> Scroller.scrollTo "y", "max", true
- scrollToTop: -> Scroller.scrollTo "y", 0, true
- scrollToLeft: -> Scroller.scrollTo "x", 0, true
- scrollToRight: -> Scroller.scrollTo "x", "max", true
+ scrollToBottom: -> Scroller.scrollTo "y", "max"
+ scrollToTop: -> Scroller.scrollTo "y", 0
+ scrollToLeft: -> Scroller.scrollTo "x", 0
+ scrollToRight: -> Scroller.scrollTo "x", "max"
scrollUp: -> Scroller.scrollBy "y", -1 * settings.get("scrollStepSize")
scrollDown: -> Scroller.scrollBy "y", settings.get("scrollStepSize")
scrollPageUp: -> Scroller.scrollBy "y", "viewSize", -1/2