mirror of
https://github.com/atom/atom.git
synced 2026-01-26 15:28:27 -05:00
Use ::positionForRow in ::updateTilesState
The algorithm is still super sloooow 🐌, but we'll fix that in a later
commit.
This commit is contained in:
@@ -168,6 +168,37 @@ describe "TextEditorPresenter", ->
|
||||
|
||||
expect(stateFn(presenter).tiles[12]).toBeUndefined()
|
||||
|
||||
it "computes each tile's height and scrollTop based on block decorations' height", ->
|
||||
presenter = buildPresenter(explicitHeight: 120, scrollTop: 0, lineHeight: 10, tileSize: 2)
|
||||
|
||||
blockDecoration1 = editor.addBlockDecorationForScreenRow(3)
|
||||
blockDecoration2 = editor.addBlockDecorationForScreenRow(5)
|
||||
presenter.setBlockDecorationDimensions(blockDecoration1, 0, 30)
|
||||
presenter.setBlockDecorationDimensions(blockDecoration2, 0, 40)
|
||||
|
||||
expect(stateFn(presenter).tiles[0].height).toBe(20)
|
||||
expect(stateFn(presenter).tiles[0].top).toBe(0)
|
||||
expect(stateFn(presenter).tiles[2].height).toBe(20 + 30)
|
||||
expect(stateFn(presenter).tiles[2].top).toBe(20)
|
||||
expect(stateFn(presenter).tiles[4].height).toBe(20 + 40)
|
||||
expect(stateFn(presenter).tiles[4].top).toBe(20 + 30 + 20)
|
||||
expect(stateFn(presenter).tiles[6].height).toBe(20)
|
||||
expect(stateFn(presenter).tiles[6].top).toBe((20 + 40) + (20 + 30) + 20)
|
||||
expect(stateFn(presenter).tiles[8]).toBeUndefined()
|
||||
|
||||
presenter.setScrollTop(20)
|
||||
|
||||
expect(stateFn(presenter).tiles[0]).toBeUndefined()
|
||||
expect(stateFn(presenter).tiles[2].height).toBe(20 + 30)
|
||||
expect(stateFn(presenter).tiles[2].top).toBe(0)
|
||||
expect(stateFn(presenter).tiles[4].height).toBe(20 + 40)
|
||||
expect(stateFn(presenter).tiles[4].top).toBe(30 + 20)
|
||||
expect(stateFn(presenter).tiles[6].height).toBe(20)
|
||||
expect(stateFn(presenter).tiles[6].top).toBe((20 + 40) + (20 + 30))
|
||||
expect(stateFn(presenter).tiles[8].height).toBe(20)
|
||||
expect(stateFn(presenter).tiles[8].top).toBe((20 + 40) + (20 + 30) + 20)
|
||||
expect(stateFn(presenter).tiles[10]).toBeUndefined()
|
||||
|
||||
it "includes state for all tiles if no external ::explicitHeight is assigned", ->
|
||||
presenter = buildPresenter(explicitHeight: null, tileSize: 2)
|
||||
expect(stateFn(presenter).tiles[0]).toBeDefined()
|
||||
|
||||
@@ -429,14 +429,14 @@ class TextEditorPresenter
|
||||
tile = @state.content.tiles[tileStartRow] ?= {}
|
||||
tile.top = @positionForRow(tileStartRow) - @scrollTop
|
||||
tile.left = -@scrollLeft
|
||||
tile.height = @tileSize * @lineHeight
|
||||
tile.height = @positionForRow(tileStartRow + @tileSize) - @positionForRow(tileStartRow)
|
||||
tile.display = "block"
|
||||
tile.zIndex = zIndex
|
||||
tile.highlights ?= {}
|
||||
|
||||
gutterTile = @lineNumberGutter.tiles[tileStartRow] ?= {}
|
||||
gutterTile.top = tileStartRow * @lineHeight - @scrollTop
|
||||
gutterTile.height = @tileSize * @lineHeight
|
||||
gutterTile.top = @positionForRow(tileStartRow) - @scrollTop
|
||||
gutterTile.height = @positionForRow(tileStartRow + @tileSize) - @positionForRow(tileStartRow)
|
||||
gutterTile.display = "block"
|
||||
gutterTile.zIndex = zIndex
|
||||
|
||||
@@ -697,7 +697,8 @@ class TextEditorPresenter
|
||||
top = 0
|
||||
for tileRow in [0..@model.getScreenLineCount()] by @tileSize
|
||||
for row in [tileRow...Math.min(tileRow + @tileSize, @model.getScreenLineCount())] by 1
|
||||
nextTop = top + @lineHeight
|
||||
blockDecorationsForCurrentRow = _.values(@blockDecorationsDimensionsByScreenRow[row])
|
||||
nextTop = top + @lineHeight + @getBlockDecorationsHeight(blockDecorationsForCurrentRow)
|
||||
if floor
|
||||
return row if nextTop > position
|
||||
else
|
||||
@@ -710,7 +711,8 @@ class TextEditorPresenter
|
||||
for tileRow in [0..@model.getScreenLineCount()] by @tileSize
|
||||
for row in [tileRow...Math.min(tileRow + @tileSize, @model.getScreenLineCount())] by 1
|
||||
return top if row is targetRow
|
||||
top += @lineHeight
|
||||
blockDecorationsForNextRow = _.values(@blockDecorationsDimensionsByScreenRow[row + 1])
|
||||
top += @lineHeight + @getBlockDecorationsHeight(blockDecorationsForNextRow)
|
||||
top
|
||||
|
||||
updateStartRow: ->
|
||||
|
||||
Reference in New Issue
Block a user