     return @index
 
   getLine: ->
-    line = @node
-    while @node.className != 'line'
-      line = @node.parentNode
-    return line
+    ancestors = this.getAncestorNodes()
+    return ancestors[ancestors.length - 1]
 
 
 class TandemRange

      
  getAttributeIntersection: ->
    attributes = null
    console.log 'leaf', this.getLeafNodes()
    _.all(this.getLeafNodes(), (node) ->
      leafAttributes = []
      while node.className != 'line'
        switch node.tagName
          when 'B' then leafAttributes['bold'] = true
          when 'I' then leafAttributes['italic'] = true
          when 'S' then leafAttributes['strike'] = true
          when 'U' then leafAttributes['underline'] = true
        node = node.parentNode
      if attributes
        _.each(attributes, (value, key) ->
          if leafAttributes[key] != true

    if range.collapsed
      return [@start.node]
    else
      return _.map(range.getNodes([3]), (node) -> 
        return node.parentNode
      )

  getLeafPositions: ->
    return _.map(this.getLeafNodes(), (node) =>
      return new TandemPosition(@editor, node, 0)
    )

  groupNodesByLine: ->
    currentLine = 0
    return _.reduce(this.getLeafPositions(), (lines, position) ->
      line = position.getLine()
      if currentLine == line
        lines[lines.length - 1].push(position.node)
      else
        lines.push([position.node])
        currentLine = line
      return lines
    , [])

  split: (position, before = true) ->
    newNode = @editor.iframeDoc.createElement(position.node.tagName)
