     super shape
 
   mousedown: (pos, idx, t) ->
-    for n in @nodes
-      if n.isHit(pos)
-        if @merging?
+    if @merging?
+      for n in @nodes
+        if n.isHit(pos)
           if n isnt @merging.node
             @mergeNodes(@merging.node, n)
             @merging = null
 
             return true
 
-    if @merging?
       @merging = null
 
     super pos, idx, t

  constructor: (shape) ->
    super shape

  default_bbox: (min: (x: 100, y: 100), len: (x: 100, y: 100))

  copyNodesFrom: (nc) ->
    @nodes = [ new ShannonFanoNode(nc.nodes, @shape, @default_bbox, "") ]

  render: (ctx, idx, t) ->
    super ctx, idx, t

  collection_dropdown_menu: shannon_fano_dropdown_menu
 
lerp2d = (t, p0, p1) ->
  if t < 0

    renderShape(ctx, @shape, .75)
    # fix line width
    ctx.scale(1/@bbox.len.x, 1/@bbox.len.y)
    ctx.fill()
    ctx.stroke()
    ctx.restore()

