Merge pull request #8098 from atom/as-tiles-z-index

Render tiles upper in the stack in front of the ones below
This commit is contained in:
Antonio Scandurra 2015-07-28 10:13:20 +02:00
commit b00c148de8
4 changed files with 37 additions and 1 deletions

View File

@ -88,6 +88,28 @@ describe "TextEditorComponent", ->
else
expect(lineNode.textContent).toBe(tokenizedLine.text)
it "renders tiles upper in the stack in front of the ones below", ->
wrapperNode.style.height = 6.5 * lineHeightInPixels + 'px'
component.measureDimensions()
nextAnimationFrame()
tilesNodes = componentNode.querySelector(".lines").querySelectorAll(".tile")
expect(tilesNodes[0].style.zIndex).toBe("2")
expect(tilesNodes[1].style.zIndex).toBe("1")
expect(tilesNodes[2].style.zIndex).toBe("0")
verticalScrollbarNode.scrollTop = 1 * lineHeightInPixels
verticalScrollbarNode.dispatchEvent(new UIEvent('scroll'))
nextAnimationFrame()
tilesNodes = componentNode.querySelector(".lines").querySelectorAll(".tile")
expect(tilesNodes[0].style.zIndex).toBe("3")
expect(tilesNodes[1].style.zIndex).toBe("2")
expect(tilesNodes[2].style.zIndex).toBe("1")
expect(tilesNodes[3].style.zIndex).toBe("0")
it "renders the currently-visible lines in a tiled fashion", ->
wrapperNode.style.height = 6.5 * lineHeightInPixels + 'px'
component.measureDimensions()

View File

@ -13,6 +13,9 @@ class LinesComponent extends TiledComponent
constructor: ({@presenter, @hostElement, @useShadowDOM, visible}) ->
@domNode = document.createElement('div')
@domNode.classList.add('lines')
@tilesNode = document.createElement("div")
@tilesNode.style.zIndex = 0
@domNode.appendChild(@tilesNode)
@cursorsComponent = new CursorsComponent
@domNode.appendChild(@cursorsComponent.getDomNode())
@ -62,7 +65,7 @@ class LinesComponent extends TiledComponent
getNewState: (state) ->
state.content
getTilesNode: -> @domNode
getTilesNode: -> @tilesNode
measureLineHeightAndDefaultCharWidth: ->
@domNode.appendChild(DummyLineNode)

View File

@ -44,6 +44,10 @@ class LinesTileComponent
@domNode.style.backgroundColor = @newState.backgroundColor
@oldState.backgroundColor = @newState.backgroundColor
if @newTileState.zIndex isnt @oldTileState.zIndex
@domNode.style.zIndex = @newTileState.zIndex
@oldTileState.zIndex = @newTileState.zIndex
if @newTileState.display isnt @oldTileState.display
@domNode.style.display = @newTileState.display
@oldTileState.display = @newTileState.display

View File

@ -322,10 +322,16 @@ class TextEditorPresenter
@tileForRow(@model.getScreenLineCount()), @tileForRow(@endRow)
)
getTilesCount: ->
Math.ceil(
(@getEndTileRow() - @getStartTileRow() + 1) / @tileSize
)
updateTilesState: ->
return unless @startRow? and @endRow? and @lineHeight?
visibleTiles = {}
zIndex = @getTilesCount() - 1
for startRow in [@getStartTileRow()..@getEndTileRow()] by @tileSize
endRow = Math.min(@model.getScreenLineCount(), startRow + @tileSize)
@ -334,6 +340,7 @@ class TextEditorPresenter
tile.left = -@scrollLeft
tile.height = @tileSize * @lineHeight
tile.display = "block"
tile.zIndex = zIndex--
tile.highlights ?= {}
gutterTile = @lineNumberGutter.tiles[startRow] ?= {}