 
   lastScreenRowForBufferRow: (bufferRow) ->
     startRow = @screenPositionFromBufferPosition([bufferRow, 0]).row
-    startRow + (@wrappedLines[bufferRow].screenLines.length - 1)
+    startRow + (@index.at(bufferRow).screenLines.length - 1)
 
   buildWrappedLinesForBufferRows: (start, end) ->
     for row in [start..end]

  setMaxLength: (@maxLength) ->
    oldRange = new Range
    oldRange.end.row = @screenLineCount() - 1
    oldRange.end.column = _.last(_.last(@wrappedLines).screenLines).text.length
    @buildWrappedLines()
    newRange = new Range
    newRange.end.row = @screenLineCount() - 1
    newRange.end.column = _.last(_.last(@wrappedLines).screenLines).text.length
    @trigger 'change', { oldRange, newRange }

  buildWrappedLines: ->
    @wrappedLines = @buildWrappedLinesForBufferRows(0, @buffer.lastRow())

  handleChange: (e) ->
    oldRange = new Range


  screenPositionFromBufferPosition: (bufferPosition, allowEOL=false) ->
    bufferPosition = Point.fromObject(bufferPosition)
    row = @index.spanForIndex(bufferPosition.row)
    column = bufferPosition.column

    screenLines = @index.at(bufferPosition.row).screenLines
    for screenLine, index in screenLines
      break if index == screenLines.length - 1
      if allowEOL
