 _ = require 'underscore'
 EventEmitter = require 'event-emitter'
+SpanIndex = require 'span-index'
 Point = require 'point'
 Range = require 'range'
 


  lastScreenRowForBufferRow: (bufferRow) ->
    startRow = @screenPositionFromBufferPosition([bufferRow, 0]).row
    startRow + (@wrappedLines[bufferRow].screenLines.length - 1)

  buildWrappedLinesForBufferRows: (start, end) ->
    for row in [start..end]

    bufferRow = e.oldRange.start.row
    oldRange.start.row = @firstScreenRowForBufferRow(e.oldRange.start.row)
    oldRange.end.row = @lastScreenRowForBufferRow(e.oldRange.end.row)
    oldRange.end.column = _.last(@index.at(e.oldRange.end.row).screenLines).text.length

    { start, end } = e.oldRange
    wrappedLines = @buildWrappedLinesForBufferRows(e.newRange.start.row, e.newRange.end.row)
    @index.splice start.row, end.row, @getSpans(wrappedLines), wrappedLines

    newRange = oldRange.copy()
    newRange.end.row = @lastScreenRowForBufferRow(e.newRange.end.row)
    newRange.end.column = _.last(@index.at(e.newRange.end.row).screenLines).text.length

    @trigger 'change', { oldRange, newRange }

