     if range.collapsed
       return [@start.node]
     else
-      return _.map(range.getNodes([3]), (node) -> return node.parentNode)
+      return _.map(range.getNodes([3]), (node) -> 
+        return node.parentNode
+      )
+
+  getLeafPositions: ->
+    return _.map(this.getLeafNodes(), (node) =>
+      return new TandemPosition(@editor, node, 0)
+    )
 
   groupNodesByLine: ->
-    currentAncestor = 0
-    arr = _.reduce(this.getLeafNodes(), (memo, node) ->
-      ancestor = node.parentNode
-      while ancestor.className != "line"
-        ancestor = ancestor.parentNode
-      if currentAncestor == ancestor
-        memo[memo.length - 1].push(node)
+    currentLine = 0
+    return _.reduce(this.getLeafPositions(), (lines, position) ->
+      line = position.getLine()
+      if currentLine == line
+        lines[lines.length - 1].push(position.node)
       else
-        memo.push([node])
-        currentAncestor = ancestor
-      return memo
+        lines.push([position.node])
+        currentLine = line
+      return lines
     , [])
-    return arr
 
   split: (position, before = true) ->
     newNode = @editor.iframeDoc.createElement(position.node.tagName)

        )
      else
        attributes = leafAttributes
    )

    return attributes || {}

    return @index

  getLine: ->
    ancestors = this.getAncestorNodes()
    return ancestors[ancestors.length - 1]


class TandemRange
