Use the new LineTopIndex in TextEditorPresenter

This commit is contained in:
Antonio Scandurra
2015-12-02 16:01:55 +01:00
parent 1f20ab5170
commit f30e4ccc9d
8 changed files with 54 additions and 113 deletions

View File

@@ -2,7 +2,7 @@
module.exports =
class FakeLinesYardstick
constructor: (@model, @presenter) ->
constructor: (@model, @presenter, @lineTopIndex) ->
@characterWidthsByScope = {}
prepareScreenRowsForMeasurement: ->
@@ -31,7 +31,7 @@ class FakeLinesYardstick
targetColumn = screenPosition.column
baseCharacterWidth = @model.getDefaultCharWidth()
top = @bottomPixelPositionForRow(targetRow)
top = @lineTopIndex.bottomPixelPositionForRow(targetRow)
left = 0
column = 0
@@ -60,48 +60,15 @@ class FakeLinesYardstick
{top, left}
rowForTopPixelPosition: (position, floor = true) ->
top = 0
for tileStartRow in [0..@model.getScreenLineCount()] by @presenter.getTileSize()
tileEndRow = Math.min(tileStartRow + @presenter.getTileSize(), @model.getScreenLineCount())
for row in [tileStartRow...tileEndRow] by 1
nextTop = top + @presenter.getScreenRowHeight(row)
if floor
return row if nextTop > position
else
return row if top >= position
top = nextTop
@model.getScreenLineCount()
topPixelPositionForRow: (targetRow) ->
top = 0
for row in [0..targetRow]
return top if targetRow is row
top += @presenter.getScreenRowHeight(row)
top
bottomPixelPositionForRow: (targetRow) ->
@topPixelPositionForRow(targetRow + 1) - @model.getLineHeightInPixels()
topPixelPositionForRows: (startRow, endRow, step) ->
results = {}
top = 0
for tileStartRow in [0..endRow] by step
tileEndRow = Math.min(tileStartRow + step, @model.getScreenLineCount())
results[tileStartRow] = top
for row in [tileStartRow...tileEndRow] by 1
top += @presenter.getScreenRowHeight(row)
results
pixelRectForScreenRange: (screenRange) ->
if screenRange.end.row > screenRange.start.row
top = @pixelPositionForScreenPosition(screenRange.start).top
left = 0
height = @topPixelPositionForRow(screenRange.end.row + 1) - top
height = @lineTopIndex.topPixelPositionForRow(screenRange.end.row + 1) - top
width = @presenter.getScrollWidth()
else
{top, left} = @pixelPositionForScreenPosition(screenRange.start, false)
height = @topPixelPositionForRow(screenRange.end.row + 1) - top
height = @lineTopIndex.topPixelPositionForRow(screenRange.end.row + 1) - top
width = @pixelPositionForScreenPosition(screenRange.end, false).left - left
{top, left, width, height}

View File

@@ -1707,13 +1707,13 @@ describe('TextEditorComponent', function () {
await nextViewUpdatePromise()
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)")
expect(component.tileNodesForLines()[1].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + 100 + 40 + "px")
expect(component.tileNodesForLines()[1].style.webkitTransform).toBe(`translate3d(0px, ${component.tileNodesForLines()[0].offsetHeight}px, 0px)`)
expect(component.tileNodesForLines()[2].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + 120 + "px")
expect(component.tileNodesForLines()[2].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + "px")
expect(component.tileNodesForLines()[2].style.webkitTransform).toBe(`translate3d(0px, ${component.tileNodesForLines()[0].offsetHeight + component.tileNodesForLines()[1].offsetHeight}px, 0px)`)
expect(component.getTopmostDOMNode().querySelector(".decoration-1")).toBeNull()
@@ -1724,7 +1724,7 @@ describe('TextEditorComponent', function () {
expect(item1.getBoundingClientRect().height).toBe(0) // hidden
expect(item2.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 3)
expect(item3.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 5 + 40)
expect(item4.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 8 + 40 + 100)
expect(item4.getBoundingClientRect().height).toBe(0) // hidden
await nextViewUpdatePromise()
@@ -1734,13 +1734,13 @@ describe('TextEditorComponent', function () {
await nextViewUpdatePromise()
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)")
expect(component.tileNodesForLines()[1].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + 100 + 60 + "px")
expect(component.tileNodesForLines()[1].style.webkitTransform).toBe(`translate3d(0px, ${component.tileNodesForLines()[0].offsetHeight}px, 0px)`)
expect(component.tileNodesForLines()[2].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + 120 + "px")
expect(component.tileNodesForLines()[2].style.height).toBe(TILE_SIZE * editor.getLineHeightInPixels() + "px")
expect(component.tileNodesForLines()[2].style.webkitTransform).toBe(`translate3d(0px, ${component.tileNodesForLines()[0].offsetHeight + component.tileNodesForLines()[1].offsetHeight}px, 0px)`)
expect(component.getTopmostDOMNode().querySelector(".decoration-1")).toBeNull()
@@ -1751,7 +1751,7 @@ describe('TextEditorComponent', function () {
expect(item1.getBoundingClientRect().height).toBe(0) // hidden
expect(item2.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 3)
expect(item3.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 5 + 60)
expect(item4.getBoundingClientRect().top).toBe(editor.getLineHeightInPixels() * 8 + 60 + 100)
expect(item4.getBoundingClientRect().height).toBe(0) // hidden
})
})

View File

@@ -5,6 +5,7 @@ TextBuffer = require 'text-buffer'
TextEditor = require '../src/text-editor'
TextEditorPresenter = require '../src/text-editor-presenter'
FakeLinesYardstick = require './fake-lines-yardstick'
LineTopIndex = require '../src/linear-line-top-index'
describe "TextEditorPresenter", ->
# These `describe` and `it` blocks mirror the structure of the ::state object.
@@ -26,12 +27,14 @@ describe "TextEditorPresenter", ->
buffer.destroy()
buildPresenterWithoutMeasurements = (params={}) ->
lineTopIndex = new LineTopIndex
_.defaults params,
model: editor
config: atom.config
contentFrameWidth: 500
lineTopIndex: lineTopIndex
presenter = new TextEditorPresenter(params)
presenter.setLinesYardstick(new FakeLinesYardstick(editor, presenter))
presenter.setLinesYardstick(new FakeLinesYardstick(editor, presenter, lineTopIndex))
presenter
buildPresenter = (params={}) ->