Redesign LinesYardstick

This commit is contained in:
Antonio Scandurra
2015-09-20 12:10:09 +02:00
parent 7b95b9923a
commit af41b71cd8
7 changed files with 85 additions and 135 deletions

View File

@@ -1,68 +0,0 @@
LinesYardstick = require '../src/lines-yardstick'
MockLinesComponent = require './mock-lines-component'
describe "LinesYardstick", ->
[editor, mockPresenter, mockLinesComponent, linesYardstick] = []
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage('language-javascript')
waitsForPromise ->
atom.project.open('sample.js').then (o) -> editor = o
runs ->
mockPresenter = {getStateForMeasurements: jasmine.createSpy()}
mockLinesComponent = new MockLinesComponent(editor)
linesYardstick = new LinesYardstick(editor, mockPresenter, mockLinesComponent)
mockLinesComponent.setDefaultFont("14px monospace")
afterEach ->
doSomething = true
it "converts screen positions to pixel positions", ->
stubState = {anything: {}}
mockPresenter.getStateForMeasurements.andReturn(stubState)
linesYardstick.prepareScreenRowsForMeasurement([0, 1, 2])
expect(mockPresenter.getStateForMeasurements).toHaveBeenCalledWith([0, 1, 2])
expect(mockLinesComponent.updateSync).toHaveBeenCalledWith(stubState)
conversionTable = [
[[0, 0], {left: 0, top: editor.getLineHeightInPixels() * 0}]
[[0, 3], {left: 24, top: editor.getLineHeightInPixels() * 0}]
[[0, 4], {left: 32, top: editor.getLineHeightInPixels() * 0}]
[[0, 5], {left: 40, top: editor.getLineHeightInPixels() * 0}]
[[1, 0], {left: 0, top: editor.getLineHeightInPixels() * 1}]
[[1, 1], {left: 0, top: editor.getLineHeightInPixels() * 1}]
[[1, 6], {left: 48, top: editor.getLineHeightInPixels() * 1}]
[[1, Infinity], {left: 240, top: editor.getLineHeightInPixels() * 1}]
]
for [point, position] in conversionTable
expect(
linesYardstick.pixelPositionForScreenPosition(point)
).toEqual(position)
mockLinesComponent.setFontForScopes(
["source.js", "storage.modifier.js"], "16px monospace"
)
linesYardstick.clearCache()
conversionTable = [
[[0, 0], {left: 0, top: editor.getLineHeightInPixels() * 0}]
[[0, 3], {left: 30, top: editor.getLineHeightInPixels() * 0}]
[[0, 4], {left: 38, top: editor.getLineHeightInPixels() * 0}]
[[0, 5], {left: 46, top: editor.getLineHeightInPixels() * 0}]
[[1, 0], {left: 0, top: editor.getLineHeightInPixels() * 1}]
[[1, 1], {left: 0, top: editor.getLineHeightInPixels() * 1}]
[[1, 6], {left: 54, top: editor.getLineHeightInPixels() * 1}]
[[1, Infinity], {left: 246, top: editor.getLineHeightInPixels() * 1}]
]
for [point, position] in conversionTable
expect(
linesYardstick.pixelPositionForScreenPosition(point)
).toEqual(position)

View File

@@ -4,15 +4,17 @@ TextBuffer = require 'text-buffer'
{Point, Range} = TextBuffer
TextEditor = require '../src/text-editor'
TextEditorPresenter = require '../src/text-editor-presenter'
LinesYardstick = require '../src/lines-yardstick'
fdescribe "TextEditorPresenter", ->
[buffer, editor] = []
describe "TextEditorPresenter", ->
[buffer, editor, linesYardstick, mockLineNodesProvider] = []
beforeEach ->
# These *should* be mocked in the spec helper, but changing that now would break packages :-(
spyOn(window, "setInterval").andCallFake window.fakeSetInterval
spyOn(window, "clearInterval").andCallFake window.fakeClearInterval
mockLineNodesProvider = {updateSync: ->}
buffer = new TextBuffer(filePath: require.resolve('./fixtures/sample.js'))
editor = new TextEditor({buffer})
waitsForPromise -> buffer.load()
@@ -37,7 +39,10 @@ fdescribe "TextEditorPresenter", ->
scrollTop: 0
scrollLeft: 0
new TextEditorPresenter(params)
presenter = new TextEditorPresenter(params)
linesYardstick = new LinesYardstick(editor, presenter, mockLineNodesProvider)
presenter.setLinesYardstick(linesYardstick)
presenter
expectValues = (actual, expected) ->
for key, value of expected
@@ -55,19 +60,6 @@ fdescribe "TextEditorPresenter", ->
expectNoStateUpdate = (presenter, fn) -> expectStateUpdatedToBe(false, presenter, fn)
describe "::getStateForMeasurements(screenRows)", ->
it "contains states for tiles of the visible rows + the supplied ones", ->
presenter = buildPresenter(explicitHeight: 6, scrollTop: 0, lineHeight: 1, tileSize: 2)
state = presenter.getStateForMeasurements([10, 11])
expect(state.content.tiles[0]).toBeDefined()
expect(state.content.tiles[2]).toBeDefined()
expect(state.content.tiles[4]).toBeDefined()
expect(state.content.tiles[6]).toBeDefined()
expect(state.content.tiles[8]).toBeUndefined()
expect(state.content.tiles[10]).toBeDefined()
expect(state.content.tiles[12]).toBeUndefined()
# These `describe` and `it` blocks mirror the structure of the ::state object.
# Please maintain this structure when adding specs for new state fields.
describe "::getState()", ->