     # the stylesheet will be removed before the animation is finished
     # so set minWidth on the element
     @treeViewEl.style.minWidth = '1px'
+    # apply new pushEditor value, then show the tree view
     @update().then =>
       # show the tree view
       @show 0
     .then =>
+      # finally dispose of everything
       @disposables.dispose()
       [@disposables, @conf, @visible] = []
     .catch error
 
   registerTreeView: (treeViewPkg) ->
+    # keep references to the tree view element
     @treeView = treeViewPkg.mainModule.createView()
     @treeViewEl = @treeView.element
     @treeViewEl.classList.add 'autohide'
 
+    # register a disposable that disposes of the references
+    # and resets the styles
     @disposables.add new Disposable =>
       @treeViewEl.classList.remove 'autohide', 'autohide-hover'
       @treeViewEl.style.position = ''

      @focusedElement.focus()
    @clearFocusedElement()

  enableHoverEvents: ->
    if @conf.showOn.match 'hover'
      @treeViewEl.classList.add 'autohide-hover'

  disableHoverEvents: ->
    if @conf.showOn.match 'hover'
      @treeViewEl.classList.remove 'autohide-hover'

  # resolves true if animation finished, false if animation cancelled
  animate: (targetWidth, delay) ->
    initialWidth = @treeViewEl.clientWidth
    duration = Math.abs targetWidth - initialWidth / (@conf.animationSpeed or Infinity)

    if @currentAnimation? and @currentAnimation.playState isnt 'finished'
      @currentAnimation.cancel()
      @currentAnimation = null
      delay = 0

    @treeViewEl.style.width = "#{initialWidth}px"
    new Promise (resolve) =>
      if targetWidth is initialWidth
        return resolve true

      @currentAnimation = animation = @treeViewEl.animate [
        {width: initialWidth}
        {width: targetWidth}
      ], {duration, delay}

      animation.onfinish = =>
        if animation.playState isnt 'finished'
          return resolve false
        @treeViewEl.style.width = "#{targetWidth}px"
        @currentAnimation = null
        resolve true
    .catch error

      @resize()
    .catch error

  # show the tree view
  show: (delay = @conf.showDelay, disableHoverEvents = false) ->
    # disable hover events on the tree view when not triggered
    # by a hover event
    @disableHoverEvents() if disableHoverEvents
    # keep a reference to the currently focused element
    # so we can restore focus when the tree view hides
    @storeFocusedElement()
    # show the content of the tree view
    @treeView.scroller[0].style.display = ''
    @animate @treeView.list[0].clientWidth, delay
    .then (finished) =>
      @visible = true
      # focus the tree view when the animation is done
      @treeView.focus() if finished

  # hide the tree view
  hide: (delay = @conf.hideDelay) ->
    @visible = false
    # enable hover events again
    @enableHoverEvents()
    # focus the element that was focused before the tree view
    # was opened
    @recoverFocus()
    @animate @conf.hiddenWidth, delay
    .then (finished) =>
      # hide the tree view content
      @treeView.scroller[0].style.display = 'none' if finished

  # toggle the tree view
  toggle: (disableHoverEvents = true) ->
    if @visible then @hide 0 else @show 0, disableHoverEvents

  # resize the tree view when its contents might change size
  resize: ->
    promiseNextTick.then() =>
      if @visible then @show 0  else @hide 0
    .catch error

  # keep a reference to the currently focused element
  storeFocusedElement: ->
    @focusedElement = document.activeElement

  # clear the reference to the element that was focused
  # when the tree view was opened
  clearFocusedElement: ->
    @focusedElement = null

  # recover focus on the element that was focused when
  # the tree view was opened
  recoverFocus: ->
    return unless @focusedElement?
    if typeof @focusedElement.focused is 'function'
