       'autohide-tree-view:hide': =>
         @hide true
       'autohide-tree-view:toggle-visible': =>
-        if @enabled
-          @disableHoverEvents()
-          @toggle()
-        else
-          atom.commands.dispatch atom.views.getView(atom.workspace), 'tree-view:toggle'
+        @toggle()
       'autohide-tree-view:enable': =>
         @enable()
       'autohide-tree-view:disable': =>

    else if e.type isnt 'mouseup'
      @hide true

  animate: do ->
    animation = null

    nextFrame = ->
      {start, duration, initialWidth, targetWidth} = animation
      animation.rafHandle = requestAnimationFrame nextFrame.bind @
      progress = (Date.now() - animation.start) / animation.duration
      if 1 <= progress
        progress = 1
        cancelAnimationFrame animation.rafHandle
        animation = null
      @treeViewResizerEl.style.width = "#{initialWidth + (targetWidth - initialWidth) * progress}px"

    (targetWidth) ->
      if animation?.rafHandle?
        cancelAnimationFrame animation.rafHandle
      initialWidth = @treeViewResizerEl.clientWidth
      start = Date.now()
      duration = Math.abs (targetWidth - initialWidth) / (@conf.animationSpeed or Infinity)
      rafHandle = requestAnimationFrame nextFrame.bind @
      animation = {targetWidth, initialWidth, start, duration, rafHandle}


  enableHoverEvents: =>
    @treeViewResizerEl.classList.add 'autohide-hover'

  disableHoverEvents: =>
    @treeViewResizerEl.classList.remove 'autohide-hover'

module.exports = new AutohideTreeView()
  deactivate: ->
    @disable()
    @disposables.dispose()
    {@treeView, @treeViewEl} = {}

  subscribeEventHandlers: =>
    @disposables.add atom.config.observe 'autohide-tree-view', (@conf) =>
