 module.exports =
 class LineMap
   constructor: ->
-    @screenLines = []
+    @lineFragments = []
 
-  insertAtBufferRow: (bufferRow, screenLines) ->
+  insertAtBufferRow: (bufferRow, lineFragments) ->
     delta = new Point
     insertIndex = 0
 
-    for screenLine in @screenLines
-      nextDelta = delta.add(screenLine.bufferDelta)
+    for lineFragment in @lineFragments
+      nextDelta = delta.add(lineFragment.bufferDelta)
       break if nextDelta.row > bufferRow
       delta = nextDelta
       insertIndex++
 
-    @screenLines[insertIndex...insertIndex] = screenLines
+    @lineFragments[insertIndex...insertIndex] = lineFragments
 
-  spliceAtBufferRow: (startRow, rowCount, screenLines) ->
-    @spliceByDelta('bufferDelta', startRow, rowCount, screenLines)
+  spliceAtBufferRow: (startRow, rowCount, lineFragments) ->
+    @spliceByDelta('bufferDelta', startRow, rowCount, lineFragments)
 
-  spliceAtScreenRow: (startRow, rowCount, screenLines) ->
-    @spliceByDelta('screenDelta', startRow, rowCount, screenLines)
+  spliceAtScreenRow: (startRow, rowCount, lineFragments) ->
+    @spliceByDelta('screenDelta', startRow, rowCount, lineFragments)
 
-  spliceByDelta: (deltaType, startRow, rowCount, screenLines) ->
+  spliceByDelta: (deltaType, startRow, rowCount, lineFragments) ->
     stopRow = startRow + rowCount
     startIndex = undefined
     stopIndex = 0
     delta = new Point
 
-    for screenLine, i in @screenLines
+    for lineFragment, i in @lineFragments
       startIndex ?= i if delta.row == startRow
-      nextDelta = delta.add(screenLine[deltaType])
+      nextDelta = delta.add(lineFragment[deltaType])
       break if nextDelta.row > stopRow
       delta = nextDelta
       stopIndex++
 
-    @screenLines[startIndex...stopIndex] = screenLines
+    @lineFragments[startIndex...stopIndex] = lineFragments
 
-  replaceBufferRows: (start, end, screenLines) ->
-    @spliceAtBufferRow(start, end - start + 1, screenLines)
+  replaceBufferRows: (start, end, lineFragments) ->
+    @spliceAtBufferRow(start, end - start + 1, lineFragments)
 
-  replaceScreenRow: (row, screenLines) ->
-    @replaceScreenRows(row, row, screenLines)
+  replaceScreenRow: (row, lineFragments) ->
+    @replaceScreenRows(row, row, lineFragments)
 
-  replaceScreenRows: (start, end, screenLines) ->
-    @spliceAtScreenRow(start, end - start + 1, screenLines)
+  replaceScreenRows: (start, end, lineFragments) ->
+    @spliceAtScreenRow(start, end - start + 1, lineFragments)
 
   lineForScreenRow: (row) ->
     @linesForScreenRows(row, row)[0]

    lines = []
    delta = new Point

    for fragment in @screenLines
      break if delta.row > endRow
      if delta.row >= startRow
        if pendingFragment
          pendingFragment = pendingFragment.concat(fragment)
        else
          pendingFragment = _.clone(fragment)
        if pendingFragment.screenDelta.row > 0
          pendingFragment.bufferDelta = new Point(1, 0)
          lines.push pendingFragment
          pendingFragment = null
      delta = delta.add(fragment.screenDelta)

    lines

  lineForBufferRow: (row) ->
    line = null
    delta = new Point
    for fragment in @screenLines
      break if delta.row > row
      if delta.row == row
        if line
          line = line.concat(fragment)
        else
          line = fragment
      delta = delta.add(fragment.bufferDelta)
    line

  bufferLineCount: ->
    delta = new Point
    for screenLine in @screenLines
      delta = delta.add(screenLine.bufferDelta)
    delta.row

  screenLineCount: ->
    delta = new Point
    for screenLine in @screenLines
      delta = delta.add(screenLine.screenDelta)
    delta.row

  lastScreenRow: ->

      screenPosition.column = Infinity

    screenDelta = new Point
    for lineFragment in @lineFragments
      nextDelta = screenDelta.add(lineFragment.screenDelta)
      break if nextDelta.isGreaterThan(screenPosition)
      screenDelta = nextDelta
