This commit is contained in:
Antonio Scandurra
2015-09-20 21:02:25 +02:00
parent af41b71cd8
commit 4318de43c9
4 changed files with 37 additions and 39 deletions

View File

@@ -60,6 +60,32 @@ describe "TextEditorPresenter", ->
expectNoStateUpdate = (presenter, fn) -> expectStateUpdatedToBe(false, presenter, fn)
describe "::getStateForMeasurements()", ->
it "contains states for tiles that need measurement, in addition to visible ones", ->
presenter = buildPresenter(explicitHeight: 4, scrollTop: 6, lineHeight: 1, tileSize: 2)
presenter.setScreenRowsToMeasure([4, 0])
state = presenter.getStateForMeasurements()
expect(state.content.tiles[0]).toBeDefined()
expect(state.content.tiles[2]).toBeUndefined()
expect(state.content.tiles[4]).toBeDefined()
expect(state.content.tiles[6]).toBeDefined()
expect(state.content.tiles[8]).toBeDefined()
expect(state.content.tiles[10]).toBeDefined()
expect(state.content.tiles[12]).toBeUndefined()
presenter.clearScreenRowsToMeasure()
state = presenter.getStateForMeasurements()
expect(state.content.tiles[0]).toBeUndefined()
expect(state.content.tiles[2]).toBeUndefined()
expect(state.content.tiles[4]).toBeUndefined()
expect(state.content.tiles[6]).toBeDefined()
expect(state.content.tiles[8]).toBeDefined()
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()", ->

View File

@@ -100,4 +100,4 @@ class LinesComponent extends TiledComponent
lineNodeForLineIdAndScreenRow: (lineId, screenRow) ->
tile = @presenter.tileForRow(screenRow)
@getComponentForTile(screenRow)?.lineNodeForLineId(lineId)
@getComponentForTile(tile)?.lineNodeForLineId(lineId)

View File

@@ -660,6 +660,7 @@ class TextEditorComponent
if @fontSize isnt oldFontSize or @fontFamily isnt oldFontFamily or @lineHeight isnt oldLineHeight
@clearPoolAfterUpdate = true
@linesYardstick.clearCache()
@measureLineHeightAndDefaultCharWidth()
if (@fontSize isnt oldFontSize or @fontFamily isnt oldFontFamily) and @performedInitialMeasurement

View File

@@ -147,8 +147,9 @@ class TextEditorPresenter
observeModel: ->
@disposables.add @model.onDidChange =>
@updateVerticalDimensions()
@updateHorizontalDimensions()
@linesYardstick.measure [@model.getLongestScreenRow()], =>
@updateVerticalDimensions()
@updateHorizontalDimensions()
@shouldUpdateHeightState = true
@shouldUpdateVerticalScrollState = true
@@ -1078,42 +1079,12 @@ class TextEditorPresenter
hasPixelPositionRequirements: ->
@lineHeight? and @baseCharacterWidth?
pixelPositionForScreenPosition: (screenPosition, clip=true) ->
screenPosition = Point.fromObject(screenPosition)
screenPosition = @model.clipScreenPosition(screenPosition) if clip
targetRow = screenPosition.row
targetColumn = screenPosition.column
baseCharacterWidth = @baseCharacterWidth
top = targetRow * @lineHeight
left = 0
column = 0
iterator = @model.tokenizedLineForScreenRow(targetRow).getTokenIterator()
while iterator.next()
characterWidths = @getScopedCharacterWidths(iterator.getScopes())
valueIndex = 0
text = iterator.getText()
while valueIndex < text.length
if iterator.isPairedCharacter()
char = text
charLength = 2
valueIndex += 2
else
char = text[valueIndex]
charLength = 1
valueIndex++
break if column is targetColumn
left += characterWidths[char] ? baseCharacterWidth unless char is '\0'
column += charLength
top -= @scrollTop
left -= @scrollLeft
{top, left}
pixelPositionForScreenPosition: (screenPosition, clip) ->
position =
@linesYardstick.pixelPositionForScreenPosition(screenPosition, clip)
position.left -= @scrollLeft
position.top -= @scrollTop
position
hasPixelRectRequirements: ->
@hasPixelPositionRequirements() and @scrollWidth?