         @selection = tool
         t.deselect() for t in @tools when t isnt tool
 
+      tool.bind 'deselect', =>
+        @selection = null if @selection is tool
+
       tool.bind 'remove', =>
         @tools.splice i, 1 for t, i in @tools when t is tool
+        @tools[@tools.length - 1]?.select() if @selection is tool
 
       tool.select()
 

    return if e.isDefaultPrevented()
    return unless @tool?
    e.preventDefault()

    {x, y} = @mouseOffset e


    {x, y}  = @mouseOffset e
    @selection.onFirstDrag [x, y]

  onKeyDown: (e) ->
    if e.which in [8, 46] # Backspace and delete
      e.preventDefault()
      @selection?.mark.destroy()

  mouseOffset: (e) ->
    {left, top} = @el.offset()
    x: (e.pageX - left) / @el.width()
