   mousedown: (pos) ->
     for n in @nodes
       if n.isHit(pos)
-        @selected =
-          node: n
-          ox: n.x # original location
-          oy: n.y
-          mx: pos.x # mousedown location
-          my: pos.y
-          t: Date.now()
+        if @merging?
+          if n isnt @merging.node
+            @mergeNodes(@merging.node, n)
+            @merging = null
+        else
+          @selected =
+            node: n
+            ox: n.x # original location
+            oy: n.y
+            mx: pos.x # mousedown location
+            my: pos.y
+            t: Date.now()
         true
+
+    if @merging?
+      @merging = null
+
     false
 
   mousemove: (pos) ->

      s = @selected
      dx = (pos.x - s.mx + s.ox) - s.node.x
      dy = (pos.y - s.my + s.oy) - s.node.y
      s.node.x += dx
      s.node.y += dy

      # TODO: apply to children

  mouseup: (pos) ->
    if @selected?

    
  render: (ctx) ->
    super ctx
    ctx.save()
    ctx.translate(@x, @y)
    setStyle(ctx, node_text_style)
    ctx.textAlign = 'center'
    ctx.textBaseline = 'middle'
