Manually set rows per page in the model

This commit is contained in:
Antonio Scandurra 2015-09-29 08:24:28 +02:00
parent 67af264c0d
commit e648d880ed
4 changed files with 22 additions and 5 deletions

View File

@ -2026,6 +2026,20 @@ describe "TextEditorPresenter", ->
} }
describe ".height", -> describe ".height", ->
it "updates model's rows per page when it changes", ->
presenter = buildPresenter(explicitHeight: 50, lineHeightInPixels: 10, horizontalScrollbarHeight: 10)
presenter.getState() # trigger state update
expect(editor.getRowsPerPage()).toBe(4)
presenter.setExplicitHeight(100)
presenter.getState() # trigger state update
expect(editor.getRowsPerPage()).toBe(9)
presenter.setHorizontalScrollbarHeight(0)
presenter.getState() # trigger state update
expect(editor.getRowsPerPage()).toBe(10)
it "tracks the computed content height if ::autoHeight is true so the editor auto-expands vertically", -> it "tracks the computed content height if ::autoHeight is true so the editor auto-expands vertically", ->
presenter = buildPresenter(explicitHeight: null, autoHeight: true) presenter = buildPresenter(explicitHeight: null, autoHeight: true)
expect(presenter.getState().height).toBe editor.getScreenLineCount() * 10 expect(presenter.getState().height).toBe editor.getScreenLineCount() * 10

View File

@ -4365,8 +4365,8 @@ describe "TextEditor", ->
describe ".pageUp/Down()", -> describe ".pageUp/Down()", ->
it "moves the cursor down one page length", -> it "moves the cursor down one page length", ->
editor.setLineHeightInPixels(10) editor.setRowsPerPage(5)
editor.setHeight(50, true)
expect(editor.getCursorBufferPosition().row).toBe 0 expect(editor.getCursorBufferPosition().row).toBe 0
editor.pageDown() editor.pageDown()
@ -4383,8 +4383,8 @@ describe "TextEditor", ->
describe ".selectPageUp/Down()", -> describe ".selectPageUp/Down()", ->
it "selects one screen height of text up or down", -> it "selects one screen height of text up or down", ->
editor.setLineHeightInPixels(10) editor.setRowsPerPage(5)
editor.setHeight(50, true)
expect(editor.getCursorBufferPosition().row).toBe 0 expect(editor.getCursorBufferPosition().row).toBe 0
editor.selectPageDown() editor.selectPageDown()

View File

@ -688,6 +688,7 @@ class TextEditorPresenter
clientHeight = @height - @horizontalScrollbarHeight clientHeight = @height - @horizontalScrollbarHeight
@model.setHeight(clientHeight, true) @model.setHeight(clientHeight, true)
@model.setRowsPerPage(Math.floor(clientHeight / @lineHeight))
unless @clientHeight is clientHeight unless @clientHeight is clientHeight
@clientHeight = clientHeight @clientHeight = clientHeight

View File

@ -2895,7 +2895,9 @@ class TextEditor extends Model
# Returns the number of rows per page # Returns the number of rows per page
getRowsPerPage: -> getRowsPerPage: ->
Math.max(1, Math.floor(@getHeight() / @getLineHeightInPixels())) Math.max(@rowsPerPage ? 1, 1)
setRowsPerPage: (@rowsPerPage) ->
### ###
Section: Config Section: Config