Scrolling to bottom renders correct lines

When we scroll more than a single screen's worth of lines, the new first visible screen row ends up exceeding the previous last rendered screen row, so we need to use the maximum of the two when deciding which new rows to render.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-05-10 15:15:34 -06:00
parent c5d2616155
commit 43ac7edf0f
2 changed files with 22 additions and 11 deletions

View File

@@ -243,27 +243,30 @@ class Editor extends View
@firstRenderedScreenRow = 0
@lastRenderedScreenRow = @getLastVisibleScreenRow()
lineElements = @buildLineElements(@firstRenderedScreenRow, @lastRenderedScreenRow)
lineElements.last().css('margin-bottom', (@getLastScreenRow() - @lastRenderedScreenRow) * @lineHeight)
@insertLineElements(0, lineElements)
@insertLineElements(0, @buildLineElements(@firstRenderedScreenRow, @lastRenderedScreenRow))
@lines.css('padding-bottom', (@getLastScreenRow() - @lastRenderedScreenRow) * @lineHeight)
updateLines: ->
firstVisibleScreenRow = @getFirstVisibleScreenRow()
lastVisibleScreenRow = @getLastVisibleScreenRow()
console.log "updateLines", firstVisibleScreenRow, lastVisibleScreenRow
# console.log "cursor screen position", @getCursorScreenPosition().inspect()
if firstVisibleScreenRow > @firstRenderedScreenRow
@lines.find('.line:first').css('margin-top', 'inherit')
console.log "removing from", @firstRenderedScreenRow, "to", firstVisibleScreenRow - 1
@removeLineElements(@firstRenderedScreenRow, firstVisibleScreenRow - 1)
@lines.find('.line:first').css('margin-top', firstVisibleScreenRow * @lineHeight)
@lines.css('padding-top', firstVisibleScreenRow * @lineHeight)
console.log @lines
if lastVisibleScreenRow > @lastRenderedScreenRow
@lines.find('.line:last').css('margin-bottom', 'inherit')
lineElements = @buildLineElements(@lastRenderedScreenRow + 1, lastVisibleScreenRow)
lineElements.last().css('margin-bottom', (@getLastScreenRow() - lastVisibleScreenRow) * @lineHeight)
@insertLineElements(@lastRenderedScreenRow + 1, lineElements)
@lastRenderedScreenRow = lastVisibleScreenRow
startRow = Math.max(@lastRenderedScreenRow + 1, firstVisibleScreenRow)
lineElements = @buildLineElements(startRow, lastVisibleScreenRow)
@insertLineElements(startRow, lineElements)
@lines.css('padding-bottom', (@getLastScreenRow() - lastVisibleScreenRow) * @lineHeight)
@firstRenderedScreenRow = firstVisibleScreenRow
@lastRenderedScreenRow = lastVisibleScreenRow
getFirstVisibleScreenRow: ->
Math.floor(@scroller.scrollTop() / @lineHeight)