 
   # For tests only.
   @reset: ->
-    mode.exit() for mode in @modes
+    for mode in @modes
+      mode.exit()
     @modes = []
     return
 

    if @options.suppressAllKeyboardEvents
      # TODO(philc): Make a let statement.
      downHanlder = @options["keydown"]
      @options["keydown"] = (event) => @alwaysSuppressPropagation => if downHanlder then downHanlder(event)
      pressHandler = @options["keypress"]
      @options["keypress"] = (event) => @alwaysSuppressPropagation => if pressHandler then pressHandler(event)

    @push
      keydown: @options.keydown || null

    return

  exit: (args...) ->
    if @modeIsExiting or not @modeIsActive
      return
    @log "deactivate:", @id
    @modeIsExiting = true

    for handler in @exitHandlers
      handler args...
    for handlerId in @handlers
      handlerStack.remove handlerId
    Mode.modes = Mode.modes.filter (mode) => mode != this

    @modeIsActive = false
