From 877eea3bd0d2779fa60ee756e2ff66145ed52c84 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 18 Dec 2015 11:07:10 +0100 Subject: [PATCH] Finish integrating LineTopIndex --- spec/text-editor-component-spec.js | 9 +++++---- spec/text-editor-presenter-spec.coffee | 23 ++++++++--------------- src/text-editor-presenter.coffee | 6 ++++-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/spec/text-editor-component-spec.js b/spec/text-editor-component-spec.js index 488c6df3a..2a686cf0c 100644 --- a/spec/text-editor-component-spec.js +++ b/spec/text-editor-component-spec.js @@ -1664,7 +1664,7 @@ describe('TextEditorComponent', function () { }) it("renders visible and yet-to-be-measured block decorations, inserting them between the appropriate lines and refreshing them as needed", async function () { - wrapperNode.style.height = 13 * lineHeightInPixels + 'px' + wrapperNode.style.height = 9 * lineHeightInPixels + 'px' component.measureDimensions() await nextViewUpdatePromise() @@ -1706,7 +1706,7 @@ describe('TextEditorComponent', function () { await nextAnimationFramePromise() - expect(component.getDomNode().querySelectorAll(".line").length).toBe(9) + expect(component.getDomNode().querySelectorAll(".line").length).toBe(7) expect(component.tileNodesForLines()[0].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + "px") expect(component.tileNodesForLines()[0].style.webkitTransform).toBe("translate3d(0px, 0px, 0px)") @@ -1731,7 +1731,7 @@ describe('TextEditorComponent', function () { await nextAnimationFramePromise() // causes the DOM to update and to retrieve new styles await nextAnimationFramePromise() // applies the changes - expect(component.getDomNode().querySelectorAll(".line").length).toBe(9) + expect(component.getDomNode().querySelectorAll(".line").length).toBe(7) expect(component.tileNodesForLines()[0].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + "px") expect(component.tileNodesForLines()[0].style.webkitTransform).toBe("translate3d(0px, 0px, 0px)") @@ -1765,10 +1765,11 @@ describe('TextEditorComponent', function () { expect(component.getTopmostDOMNode().querySelector(".decoration-1")).toBeNull() expect(component.getTopmostDOMNode().querySelector(".decoration-2")).toBe(item2) expect(component.getTopmostDOMNode().querySelector(".decoration-3")).toBe(item3) - expect(component.getTopmostDOMNode().querySelector(".decoration-4")).toBeNull() + expect(component.getTopmostDOMNode().querySelector(".decoration-4")).toBe(item4) expect(item2.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 3) expect(item3.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 5 + 20) + expect(item4.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 8 + 20 + 100) }) it("correctly sets screen rows on elements, both initially and when decorations move", async function () { diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index 9bd85c7a9..98285c7b2 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -2150,12 +2150,12 @@ describe "TextEditorPresenter", -> expectValues stateForBlockDecoration(presenter, blockDecoration2), { decoration: blockDecoration2 screenRow: 4 - isVisible: false + isVisible: true } expectValues stateForBlockDecoration(presenter, blockDecoration3), { decoration: blockDecoration3 screenRow: 4 - isVisible: false + isVisible: true } expectValues stateForBlockDecoration(presenter, blockDecoration4), { decoration: blockDecoration4 @@ -2196,23 +2196,16 @@ describe "TextEditorPresenter", -> screenRow: 4 isVisible: false } - expect(stateForBlockDecoration(presenter, blockDecoration4)).toBeUndefined() + expectValues stateForBlockDecoration(presenter, blockDecoration4), { + decoration: blockDecoration4 + screenRow: 10 + isVisible: true + } presenter.invalidateBlockDecorationDimensions(blockDecoration1) presenter.setBlockDecorationDimensions(blockDecoration2, 0, 10) presenter.setBlockDecorationDimensions(blockDecoration3, 0, 10) - expectValues stateForBlockDecoration(presenter, blockDecoration1), { - decoration: blockDecoration1 - screenRow: 0 - isVisible: false - } - expect(stateForBlockDecoration(presenter, blockDecoration2)).toBeUndefined() - expect(stateForBlockDecoration(presenter, blockDecoration3)).toBeUndefined() - expect(stateForBlockDecoration(presenter, blockDecoration4)).toBeUndefined() - - presenter.setScrollTop(140) - expectValues stateForBlockDecoration(presenter, blockDecoration1), { decoration: blockDecoration1 screenRow: 0 @@ -2226,7 +2219,6 @@ describe "TextEditorPresenter", -> isVisible: true } - describe ".overlays", -> [item] = [] stateForOverlay = (presenter, decoration) -> @@ -3091,6 +3083,7 @@ describe "TextEditorPresenter", -> expectStateUpdate presenter, -> presenter.setLineHeight(Math.ceil(1.0 * explicitHeight / marker3.getBufferRange().end.row)) decorationState = getContentForGutterWithName(presenter, 'test-gutter') + expect(decorationState[decoration1.id].top).toBeDefined() expect(decorationState[decoration2.id].top).toBeDefined() expect(decorationState[decoration3.id].top).toBeDefined() diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 6c90c4f27..0b8bfbbc9 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -638,7 +638,7 @@ class TextEditorPresenter @endRow = Math.min( @model.getScreenLineCount(), - @lineTopIndex.rowForPixelPosition(@scrollTop + @height + @lineHeight) + @lineTopIndex.rowForPixelPosition(@scrollTop + @height + (2 * @lineHeight - 1)) ) updateRowsPerPage: -> @@ -1059,8 +1059,10 @@ class TextEditorPresenter @blockDecorationsByScreenRow[screenRow].push(decoration) updateBlockDecorationState: (decoration, screenRow) -> + startRow = @getStartTileRow() + endRow = @getEndTileRow() + @tileSize hasntMeasuredDecoration = !@blockDecorationsPresenter.measuredDecorations.has(decoration) - isVisible = @startRow <= screenRow < @endRow || screenRow is @mouseWheelScreenRow + isVisible = startRow <= screenRow < endRow || screenRow is @mouseWheelScreenRow if isVisible or hasntMeasuredDecoration @state.content.blockDecorations[decoration.id] = {decoration, screenRow, isVisible}