 
     unless keyHandler
       keyHandler = handlerStack.push
-        keydown: (event) -> lastEvent = event
+        keydown: -> lastEvent = event
         keyup: -> time += 1
 
     axisName = scrollProperties[direction].axisName


    mostRecentActivationTime = activationTime = ++time

    # Duration in ms. Allow a bit longer for longer scrolls.
    duration = 100 + 25 * Math.log Math.abs amount

    # Round away from 0, so that we don't leave any requested scroll amount unscrolled.
    roundOut = if 0 <= amount then Math.ceil else Math.floor
    delta = roundOut(amount / duration)

    animatorId = null
    start = null
    scrolledAmount = 0

    shouldStopScrolling = (progress) ->
      # If activationTime == time, then this is the most recently-activated animator and we haven't yet seen
      # its keyup event, so keep going; otherwise, check progress and duration.
      if activationTime == time then false else duration <= progress

    animate = (timestamp) ->
      start ?= timestamp

      # FIXME(smblott) This calculation is not correctly calibrated:
      #   - A `j` with smooth scrolling does not take you to the same place as a `j` with jump scrolling.
      #   - A `j` followed by `k` does not take you back to exactly where you started.
      progress = timestamp - start
      scrollDelta = roundOut(delta * progress) - scrolledAmount
      scrolledAmount += scrollDelta

      if not performScroll(element, axisName, scrollDelta, false) or shouldStopScrolling progress
          # One final call of performScroll to check the visibility of the activated element.
          performScroll(element, axisName, 0, true)
          window.cancelAnimationFrame(animatorId)
      else
        animatorId = window.requestAnimationFrame(animate)

    animatorId = window.requestAnimationFrame(animate)

Scroller =
  init: (frontendSettings) ->

  element[axisName] = before
  before != after

# Find the element which we should and can scroll (or document.body).
findScrollableElement = (element, direction, amount, factor = 1) ->
  axisName = scrollProperties[direction].axisName
  while element != document.body and
