Account for overdrawMargin of startRow when computing the endRow

This commit is contained in:
Nathan Sobo 2015-01-19 15:03:40 -07:00
parent 143183aa25
commit 2296d2d378
2 changed files with 11 additions and 1 deletions

View File

@ -86,6 +86,13 @@ describe "TextEditorPresenter", ->
# rows beyond the end of the content are not rendered # rows beyond the end of the content are not rendered
it "contains the lines that are visible on screen, plus and minus the overdraw margin", ->
presenter = new TextEditorPresenter(model: editor, clientHeight: 25, scrollTop: 50, lineHeight: 10, lineOverdrawMargin: 1)
expect(presenter.state.lines[editor.tokenizedLineForScreenRow(3).id]).toBeUndefined()
expect(presenter.state.lines[editor.tokenizedLineForScreenRow(4).id]).toBeDefined()
expect(presenter.state.lines[editor.tokenizedLineForScreenRow(9).id]).toBeDefined()
expect(presenter.state.lines[editor.tokenizedLineForScreenRow(10).id]).toBeUndefined()
it "uses the computed scrollWidth as the length of each line", -> it "uses the computed scrollWidth as the length of each line", ->
line0 = editor.tokenizedLineForScreenRow(0) line0 = editor.tokenizedLineForScreenRow(0)
line1 = editor.tokenizedLineForScreenRow(1) line1 = editor.tokenizedLineForScreenRow(1)

View File

@ -56,7 +56,10 @@ class TextEditorPresenter
Math.max(0, startRow) Math.max(0, startRow)
getEndRow: -> getEndRow: ->
endRow = @getStartRow() + Math.ceil(@clientHeight / @lineHeight) + 1 + @lineOverdrawMargin startRow = @getStartRow()
visibleLinesCount = Math.ceil(@clientHeight / @lineHeight) + 1
overdrawMargin = @lineOverdrawMargin + Math.min(@lineOverdrawMargin, startRow)
endRow = startRow + visibleLinesCount + overdrawMargin
Math.min(@model.getScreenLineCount(), endRow) Math.min(@model.getScreenLineCount(), endRow)
getScrollWidth: -> getScrollWidth: ->