From 9ea62673d2d1042260679f2ff1771292ae22f1ac Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 27 Aug 2015 12:15:55 +0200 Subject: [PATCH] Put a decreasing `z-index` on line-numbers tiles --- spec/text-editor-component-spec.coffee | 22 ++++++++++++++++++++++ src/line-numbers-tile-component.coffee | 4 ++++ src/text-editor-presenter.coffee | 4 +++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/spec/text-editor-component-spec.coffee b/spec/text-editor-component-spec.coffee index 84d8cc1c7..6c3b9f104 100644 --- a/spec/text-editor-component-spec.coffee +++ b/spec/text-editor-component-spec.coffee @@ -601,6 +601,28 @@ describe "TextEditorComponent", -> expect(lineNode.offsetTop).toBe(top) expect(lineNode.textContent).toBe(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(".line-numbers").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(".line-numbers").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 "gives the line numbers container the same height as the wrapper node", -> linesNode = componentNode.querySelector(".line-numbers") diff --git a/src/line-numbers-tile-component.coffee b/src/line-numbers-tile-component.coffee index cf58c54f3..da3d6e749 100644 --- a/src/line-numbers-tile-component.coffee +++ b/src/line-numbers-tile-component.coffee @@ -42,6 +42,10 @@ class LineNumbersTileComponent @domNode.style['-webkit-transform'] = "translate3d(0, #{@newTileState.top}px, 0px)" @oldTileState.top = @newTileState.top + if @newTileState.zIndex isnt @oldTileState.zIndex + @domNode.style.zIndex = @newTileState.zIndex + @oldTileState.zIndex = @newTileState.zIndex + if @newState.maxLineNumberDigits isnt @oldState.maxLineNumberDigits node.remove() for id, node of @lineNumberNodesById @oldState.tiles[@id] = {lineNumbers: {}} diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 5fd986da3..574c6ca8e 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -344,18 +344,20 @@ class TextEditorPresenter tile.left = -@scrollLeft tile.height = @tileSize * @lineHeight tile.display = "block" - tile.zIndex = zIndex-- + tile.zIndex = zIndex tile.highlights ?= {} gutterTile = @lineNumberGutter.tiles[startRow] ?= {} gutterTile.top = startRow * @lineHeight - @scrollTop gutterTile.height = @tileSize * @lineHeight gutterTile.display = "block" + gutterTile.zIndex = zIndex @updateLinesState(tile, startRow, endRow) if @shouldUpdateLinesState @updateLineNumbersState(gutterTile, startRow, endRow) if @shouldUpdateLineNumbersState visibleTiles[startRow] = true + zIndex-- if @mouseWheelScreenRow? and @model.tokenizedLineForScreenRow(@mouseWheelScreenRow)? mouseWheelTile = @tileForRow(@mouseWheelScreenRow)