Delegate getFirst/LastVisibleScreenRow from model to component

This commit is contained in:
Nathan Sobo
2017-04-18 16:28:37 -06:00
committed by Antonio Scandurra
parent 19f5535d68
commit 493b735740
2 changed files with 16 additions and 8 deletions

View File

@@ -2483,6 +2483,17 @@ describe('TextEditorComponent', () => {
expect(component.getScrollContainerWidth()).toBe(100)
expect(Grim.deprecate.callCount).toBe(2)
})
it('delegates getFirstVisibleScreenRow, getLastVisibleScreenRow, and getVisibleRowRange to the component', async () => {
const {component, element, editor} = buildComponent({rowsPerTile: 3, autoHeight: false})
element.style.height = 4 * component.measurements.lineHeight + 'px'
await component.getNextUpdatePromise()
await setScrollTop(component, 5 * component.getLineHeight())
expect(editor.getFirstVisibleScreenRow()).toBe(component.getFirstVisibleRow())
expect(editor.getLastVisibleScreenRow()).toBe(component.getLastVisibleRow())
expect(editor.getVisibleRowRange()).toEqual([component.getFirstVisibleRow(), component.getLastVisibleRow()])
})
})
})

View File

@@ -3686,17 +3686,14 @@ class TextEditor extends Model
getFirstVisibleScreenRow: -> @firstVisibleScreenRow
getFirstVisibleScreenRow: ->
@getElement().component.getFirstVisibleRow()
getLastVisibleScreenRow: ->
if @height? and @lineHeightInPixels?
Math.min(@firstVisibleScreenRow + Math.floor(@height / @lineHeightInPixels), @getScreenLineCount() - 1)
else
null
@getElement().component.getLastVisibleRow()
getVisibleRowRange: ->
if lastVisibleScreenRow = @getLastVisibleScreenRow()
[@firstVisibleScreenRow, lastVisibleScreenRow]
else
null
[@getFirstVisibleScreenRow(), @getLastVisibleScreenRow()]
setFirstVisibleScreenColumn: (@firstVisibleScreenColumn) ->
getFirstVisibleScreenColumn: -> @firstVisibleScreenColumn