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

@@ -401,7 +401,7 @@ describe "Editor", ->
expectedMarginBottom = (buffer.numLines() - 6) * editor.lineHeight
expect(editor.lines.find('.line:last').css('margin-bottom')).toBe "#{expectedMarginBottom}px"
fit "when the lines are scrolled down, removes lines that become invisible and build lines that are become visisble", ->
it "when the lines are scrolled down, removes lines that become invisible and builds lines that become visisble", ->
editor.scroller.scrollTop(editor.lineHeight * 2.5)
editor.scroller.trigger 'scroll'
@@ -416,6 +416,14 @@ describe "Editor", ->
expect(editor.lines.find('.line:first').text()).toBe buffer.lineForRow(3)
expect(editor.lines.find('.line:last').text()).toBe buffer.lineForRow(8)
fit "when the scroller is scrolled to the end, removes lines that become invisible and builds lines that become visible", ->
editor.scroller.scrollBottom(editor.scroller[0].scrollHeight)
editor.scroller.trigger 'scroll'
expect(editor.lines.find('.line').length).toBe 6
expect(editor.lines.find('.line:first').text()).toBe buffer.lineForRow(7)
expect(editor.lines.find('.line:last').text()).toBe buffer.lineForRow(12)
it "adjusts margins to account for non-rendered lines", ->
editor.scroller.scrollTop(editor.lineHeight * 2.5)
editor.scroller.trigger 'scroll'

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)