     @onfocus = =>
       if document.activeElement == this and @model.getInput()
         @focusLast()
+
+    # determine if we should scroll down
+    @shouldScroll = true
+    @items.onscroll = throttle (=> @shouldScroll = @isVisible @lastElement()), 150
     # scroll down on subtree modifications if last element is visible
-    @resizer.listenTo @items, => @scrollDownIfVisible()()
+    @resizer.listenTo @items, => if @shouldScroll then @scrollDown()()
     for item in @model.items
       @addItem item
     atom.config.observe 'editor.fontFamily', (value) =>

  lastCell: -> @queryLast @items, '.cell'

  lastDivider: -> @queryLast @items, '.divider'

  isVisible: (pane, view) ->
    if !view? then [pane, view] = [@, pane]

    @isLoading = l

  # Scrolling
  scrollDown: -> throttle (=> delay (=> @lastElement().scrollIntoView()), 20), 130, {leading: false}

  lock: (f) ->
    if @isVisible @lastElement()
      @scrollDown()()
    f()

module.exports = ConsoleElement = document.registerElement 'ink-console', prototype: ConsoleElement.prototype
