Better rows per page calculation

This commit is contained in:
Antonio Scandurra
2015-09-30 09:17:43 +02:00
parent 5cfc5b67ae
commit cc98cab917
2 changed files with 11 additions and 1 deletions

View File

@@ -2040,6 +2040,10 @@ describe "TextEditorPresenter", ->
presenter.getState() # trigger state update
expect(editor.getRowsPerPage()).toBe(10)
presenter.setLineHeight(5)
presenter.getState() # trigger state update
expect(editor.getRowsPerPage()).toBe(20)
it "tracks the computed content height if ::autoHeight is true so the editor auto-expands vertically", ->
presenter = buildPresenter(explicitHeight: null, autoHeight: true)
expect(presenter.getState().height).toBe editor.getScreenLineCount() * 10

View File

@@ -72,6 +72,7 @@ class TextEditorPresenter
@updateScrollPosition()
@updateStartRow()
@updateEndRow()
@updateRowsPerPage()
@updateCommonGutterState()
@updateReflowState()
@@ -641,6 +642,12 @@ class TextEditorPresenter
endRow = startRow + visibleLinesCount
@endRow = Math.min(@model.getScreenLineCount(), endRow)
updateRowsPerPage: ->
rowsPerPage = Math.floor(@getClientHeight() / @lineHeight)
if rowsPerPage isnt @rowsPerPage
@rowsPerPage = rowsPerPage
@model.setRowsPerPage(@rowsPerPage)
updateScrollWidth: ->
return unless @contentWidth? and @clientWidth?
@@ -688,7 +695,6 @@ class TextEditorPresenter
clientHeight = @height - @horizontalScrollbarHeight
@model.setHeight(clientHeight, true)
@model.setRowsPerPage(Math.floor(clientHeight / @lineHeight))
unless @clientHeight is clientHeight
@clientHeight = clientHeight