mirror of
https://github.com/atom/atom.git
synced 2026-02-10 06:35:00 -05:00
Use an updated version of LineTopIndex
This commit is contained in:
@@ -31,7 +31,7 @@ class FakeLinesYardstick
|
||||
targetColumn = screenPosition.column
|
||||
baseCharacterWidth = @model.getDefaultCharWidth()
|
||||
|
||||
top = @lineTopIndex.bottomPixelPositionForRow(targetRow)
|
||||
top = @lineTopIndex.pixelPositionForRow(targetRow)
|
||||
left = 0
|
||||
column = 0
|
||||
|
||||
@@ -61,14 +61,14 @@ class FakeLinesYardstick
|
||||
{top, left}
|
||||
|
||||
pixelRectForScreenRange: (screenRange) ->
|
||||
top = @lineTopIndex.pixelPositionForRow(screenRange.start.row)
|
||||
if screenRange.end.row > screenRange.start.row
|
||||
top = @pixelPositionForScreenPosition(screenRange.start).top
|
||||
left = 0
|
||||
height = @lineTopIndex.topPixelPositionForRow(screenRange.end.row + 1) - top
|
||||
height = @lineTopIndex.pixelPositionForRow(screenRange.end.row) - top + @model.getLineHeightInPixels()
|
||||
width = @presenter.getScrollWidth()
|
||||
else
|
||||
{top, left} = @pixelPositionForScreenPosition(screenRange.start, false)
|
||||
height = @lineTopIndex.topPixelPositionForRow(screenRange.end.row + 1) - top
|
||||
{left} = @pixelPositionForScreenPosition(screenRange.start, false)
|
||||
height = @lineTopIndex.pixelPositionForRow(screenRange.end.row) - top + @model.getLineHeightInPixels()
|
||||
width = @pixelPositionForScreenPosition(screenRange.end, false).left - left
|
||||
|
||||
{top, left, width, height}
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
/** @babel */
|
||||
|
||||
const LineTopIndex = require('../src/linear-line-top-index')
|
||||
|
||||
describe("LineTopIndex", function () {
|
||||
let lineTopIndex
|
||||
|
||||
beforeEach(function () {
|
||||
lineTopIndex = new LineTopIndex()
|
||||
lineTopIndex.setDefaultLineHeight(10)
|
||||
lineTopIndex.setMaxRow(12)
|
||||
})
|
||||
|
||||
describe("::topPixelPositionForRow(row)", function () {
|
||||
it("performs the simple math when there are no block decorations", function () {
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(40)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(50)
|
||||
expect(lineTopIndex.topPixelPositionForRow(12)).toBe(120)
|
||||
expect(lineTopIndex.topPixelPositionForRow(13)).toBe(120)
|
||||
expect(lineTopIndex.topPixelPositionForRow(14)).toBe(120)
|
||||
|
||||
lineTopIndex.splice(0, 2, 3)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(40)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(50)
|
||||
expect(lineTopIndex.topPixelPositionForRow(12)).toBe(120)
|
||||
expect(lineTopIndex.topPixelPositionForRow(13)).toBe(130)
|
||||
expect(lineTopIndex.topPixelPositionForRow(14)).toBe(130)
|
||||
})
|
||||
|
||||
it("takes into account inserted and removed blocks", function () {
|
||||
let block1 = lineTopIndex.insertBlock(0, 10)
|
||||
let block2 = lineTopIndex.insertBlock(3, 20)
|
||||
let block3 = lineTopIndex.insertBlock(5, 20)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(1)).toBe(20)
|
||||
expect(lineTopIndex.topPixelPositionForRow(2)).toBe(30)
|
||||
expect(lineTopIndex.topPixelPositionForRow(3)).toBe(40)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(70)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(80)
|
||||
expect(lineTopIndex.topPixelPositionForRow(6)).toBe(110)
|
||||
|
||||
lineTopIndex.removeBlock(block1)
|
||||
lineTopIndex.removeBlock(block3)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(1)).toBe(10)
|
||||
expect(lineTopIndex.topPixelPositionForRow(2)).toBe(20)
|
||||
expect(lineTopIndex.topPixelPositionForRow(3)).toBe(30)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(60)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(70)
|
||||
expect(lineTopIndex.topPixelPositionForRow(6)).toBe(80)
|
||||
})
|
||||
|
||||
it("moves blocks down/up when splicing regions", function () {
|
||||
let block1 = lineTopIndex.insertBlock(3, 20)
|
||||
let block2 = lineTopIndex.insertBlock(5, 30)
|
||||
|
||||
lineTopIndex.splice(0, 0, 4)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(6)).toBe(60)
|
||||
expect(lineTopIndex.topPixelPositionForRow(7)).toBe(70)
|
||||
expect(lineTopIndex.topPixelPositionForRow(8)).toBe(100)
|
||||
expect(lineTopIndex.topPixelPositionForRow(9)).toBe(110)
|
||||
expect(lineTopIndex.topPixelPositionForRow(10)).toBe(150)
|
||||
expect(lineTopIndex.topPixelPositionForRow(11)).toBe(160)
|
||||
|
||||
lineTopIndex.splice(0, 6, 2)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(3)).toBe(30)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(60)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(70)
|
||||
expect(lineTopIndex.topPixelPositionForRow(6)).toBe(110)
|
||||
|
||||
lineTopIndex.splice(2, 4, 0)
|
||||
|
||||
expect(lineTopIndex.topPixelPositionForRow(0)).toBe(0)
|
||||
expect(lineTopIndex.topPixelPositionForRow(1)).toBe(10)
|
||||
expect(lineTopIndex.topPixelPositionForRow(2)).toBe(20)
|
||||
expect(lineTopIndex.topPixelPositionForRow(3)).toBe(80)
|
||||
expect(lineTopIndex.topPixelPositionForRow(4)).toBe(90)
|
||||
expect(lineTopIndex.topPixelPositionForRow(5)).toBe(100)
|
||||
expect(lineTopIndex.topPixelPositionForRow(6)).toBe(110)
|
||||
expect(lineTopIndex.topPixelPositionForRow(7)).toBe(120)
|
||||
expect(lineTopIndex.topPixelPositionForRow(8)).toBe(130)
|
||||
expect(lineTopIndex.topPixelPositionForRow(9)).toBe(130)
|
||||
})
|
||||
})
|
||||
|
||||
describe("::rowForTopPixelPosition(top)", function () {
|
||||
it("performs the simple math when there are no block decorations", function () {
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(40)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(44)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(46)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(50)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(120)).toBe(12)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(130)).toBe(12)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(140)).toBe(12)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(145)).toBe(12)
|
||||
|
||||
lineTopIndex.splice(0, 2, 3)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(40)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(50)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(120)).toBe(12)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(130)).toBe(13)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(140)).toBe(13)
|
||||
})
|
||||
|
||||
it("takes into account inserted and removed blocks", function () {
|
||||
let block1 = lineTopIndex.insertBlock(0, 10)
|
||||
let block2 = lineTopIndex.insertBlock(3, 20)
|
||||
let block3 = lineTopIndex.insertBlock(5, 20)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(6)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(10)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(12)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(17)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(20)).toBe(1)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(30)).toBe(2)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(40)).toBe(3)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(70)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(80)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(90)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(95)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(106)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(110)).toBe(6)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(160)).toBe(11)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(166)).toBe(11)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(170)).toBe(12)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(240)).toBe(12)
|
||||
|
||||
lineTopIndex.removeBlock(block1)
|
||||
lineTopIndex.removeBlock(block3)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(10)).toBe(1)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(20)).toBe(2)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(30)).toBe(3)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(60)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(70)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(80)).toBe(6)
|
||||
})
|
||||
|
||||
it("moves blocks down/up when splicing regions", function () {
|
||||
let block1 = lineTopIndex.insertBlock(3, 20)
|
||||
let block2 = lineTopIndex.insertBlock(5, 30)
|
||||
|
||||
lineTopIndex.splice(0, 0, 4)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(60)).toBe(6)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(70)).toBe(7)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(100)).toBe(8)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(110)).toBe(9)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(150)).toBe(10)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(160)).toBe(11)
|
||||
|
||||
lineTopIndex.splice(0, 6, 2)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(30)).toBe(3)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(60)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(70)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(110)).toBe(6)
|
||||
|
||||
lineTopIndex.splice(2, 4, 0)
|
||||
|
||||
expect(lineTopIndex.rowForTopPixelPosition(0)).toBe(0)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(10)).toBe(1)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(20)).toBe(2)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(80)).toBe(3)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(90)).toBe(4)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(100)).toBe(5)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(110)).toBe(6)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(120)).toBe(7)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(130)).toBe(8)
|
||||
expect(lineTopIndex.rowForTopPixelPosition(130)).toBe(8)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -57,9 +57,10 @@ describe "LinesYardstick", ->
|
||||
textNodes
|
||||
|
||||
editor.setLineHeightInPixels(14)
|
||||
lineTopIndex = new LineTopIndex()
|
||||
lineTopIndex.setDefaultLineHeight(editor.getLineHeightInPixels())
|
||||
lineTopIndex.setMaxRow(editor.getScreenLineCount())
|
||||
lineTopIndex = new LineTopIndex({
|
||||
maxRow: editor.getScreenLineCount(),
|
||||
defaultLineHeight: editor.getLineHeightInPixels()
|
||||
})
|
||||
linesYardstick = new LinesYardstick(editor, mockPresenter, mockLineNodesProvider, lineTopIndex, atom.grammars)
|
||||
|
||||
afterEach ->
|
||||
|
||||
@@ -27,7 +27,10 @@ describe "TextEditorPresenter", ->
|
||||
buffer.destroy()
|
||||
|
||||
buildPresenterWithoutMeasurements = (params={}) ->
|
||||
lineTopIndex = new LineTopIndex
|
||||
lineTopIndex = new LineTopIndex({
|
||||
maxRow: editor.getScreenLineCount(),
|
||||
defaultLineHeight: editor.getLineHeightInPixels()
|
||||
})
|
||||
_.defaults params,
|
||||
model: editor
|
||||
config: atom.config
|
||||
@@ -526,8 +529,6 @@ describe "TextEditorPresenter", ->
|
||||
presenter = buildPresenter(scrollTop: 0, lineHeight: 10)
|
||||
expect(presenter.getState().verticalScrollbar.scrollHeight).toBe editor.getScreenLineCount() * 10
|
||||
|
||||
# Setting `null` as the DOM element, as it doesn't really matter here.
|
||||
# Maybe a signal that we should separate models from views?
|
||||
blockDecoration1 = editor.addBlockDecorationForScreenRow(0, null)
|
||||
blockDecoration2 = editor.addBlockDecorationForScreenRow(3, null)
|
||||
blockDecoration3 = editor.addBlockDecorationForScreenRow(7, null)
|
||||
@@ -719,8 +720,6 @@ describe "TextEditorPresenter", ->
|
||||
presenter = buildPresenter(scrollTop: 0, lineHeight: 10)
|
||||
expect(presenter.getState().verticalScrollbar.scrollHeight).toBe editor.getScreenLineCount() * 10
|
||||
|
||||
# Setting `null` as the DOM element, as it doesn't really matter here.
|
||||
# Maybe a signal that we should separate models from views?
|
||||
blockDecoration1 = editor.addBlockDecorationForScreenRow(0, null)
|
||||
blockDecoration2 = editor.addBlockDecorationForScreenRow(3, null)
|
||||
blockDecoration3 = editor.addBlockDecorationForScreenRow(7, null)
|
||||
@@ -3041,8 +3040,8 @@ describe "TextEditorPresenter", ->
|
||||
presenter.setBlockDecorationDimensions(blockDecoration3, 0, 7)
|
||||
|
||||
decorationState = getContentForGutterWithName(presenter, 'test-gutter')
|
||||
expect(decorationState[decoration1.id].top).toBe lineHeight * marker1.getScreenRange().start.row
|
||||
expect(decorationState[decoration1.id].height).toBe lineHeight * marker1.getScreenRange().getRowCount() + 3
|
||||
expect(decorationState[decoration1.id].top).toBe lineHeight * marker1.getScreenRange().start.row + 3
|
||||
expect(decorationState[decoration1.id].height).toBe lineHeight * marker1.getScreenRange().getRowCount()
|
||||
expect(decorationState[decoration1.id].item).toBe decorationItem
|
||||
expect(decorationState[decoration1.id].class).toBe 'test-class'
|
||||
expect(decorationState[decoration2.id].top).toBe lineHeight * marker2.getScreenRange().start.row + 3 + 5
|
||||
@@ -3286,8 +3285,6 @@ describe "TextEditorPresenter", ->
|
||||
presenter = buildPresenter(scrollTop: 0, lineHeight: 10)
|
||||
expect(presenter.getState().verticalScrollbar.scrollHeight).toBe editor.getScreenLineCount() * 10
|
||||
|
||||
# Setting `null` as the DOM element, as it doesn't really matter here.
|
||||
# Maybe a signal that we should separate models from views?
|
||||
blockDecoration1 = editor.addBlockDecorationForScreenRow(0, null)
|
||||
blockDecoration2 = editor.addBlockDecorationForScreenRow(3, null)
|
||||
blockDecoration3 = editor.addBlockDecorationForScreenRow(7, null)
|
||||
|
||||
Reference in New Issue
Block a user