   screenLinesForRows: (startRow, endRow) ->
     @screenLines[startRow..endRow]
 
+  stateForRow: (row) ->
+    @screenLines[row]?.state ? 'start'
+
   destroy: ->
     @buffer.off ".highlighter#{@id}"
 

    # each line until the line's new state matches the previous state. this covers
    # cases like inserting a /* needing to comment out lines below until we see a */
    for row in [newRange.end.row...@buffer.getLastRow()]
      break if @screenLines[row].state == previousState
      nextRow = row + 1
      previousState = @screenLines[nextRow].state
      @screenLines[nextRow] = @buildScreenLineForRow(@screenLines[row].state, nextRow)

    # if highlighting spilled beyond the bounds of the textual change, update
    # the pre and post range to reflect area of highlight changes

  handleBufferChange: (e) ->
    oldRange = e.oldRange.copy()
    newRange = e.newRange.copy()
    previousState = @stateForRow(oldRange.end.row) # used in spill detection below

    startState = @stateForRow(newRange.start.row - 1)
    @screenLines[oldRange.start.row..oldRange.end.row] =
      @buildScreenLinesForRows(startState, newRange.start.row, newRange.end.row)

