This commit is contained in:
Antonio Scandurra
2015-09-17 16:26:55 +02:00
parent be843cc4df
commit 2ad336c649
3 changed files with 22 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ describe "LinesYardstick", ->
mockLineNodesProvider.setFontForScopes(
["source.js", "storage.modifier.js"], "16px monospace"
)
linesYardstick.clearCache()
conversionTable = [
[[0, 0], {left: 0, top: editor.getLineHeightInPixels() * 0}]
@@ -56,3 +57,19 @@ describe "LinesYardstick", ->
expect(
linesYardstick.pixelPositionForScreenPosition(point)
).toEqual(position)
it "does not compute the same position twice unless the cache gets cleared", ->
mockLineNodesProvider.setDefaultFont("14px monospace")
oldPosition1 = linesYardstick.pixelPositionForScreenPosition([0, 5])
oldPosition2 = linesYardstick.pixelPositionForScreenPosition([1, 4])
mockLineNodesProvider.setDefaultFont("16px monospace")
expect(linesYardstick.pixelPositionForScreenPosition([0, 5])).toEqual(oldPosition1)
expect(linesYardstick.pixelPositionForScreenPosition([1, 4])).toEqual(oldPosition2)
linesYardstick.clearCache()
expect(linesYardstick.pixelPositionForScreenPosition([0, 5])).not.toEqual(oldPosition1)
expect(linesYardstick.pixelPositionForScreenPosition([1, 4])).not.toEqual(oldPosition2)

View File

@@ -9,6 +9,9 @@ class LinesYardstick
@rangeForMeasurement = document.createRange()
@cachedPositionsByLineId = {}
clearCache: ->
@cachedPositionsByLineId = {}
pixelPositionForScreenPosition: (screenPosition, clip=true) ->
screenPosition = Point.fromObject(screenPosition)
screenPosition = @model.clipScreenPosition(screenPosition) if clip

View File

@@ -1046,6 +1046,8 @@ class TextEditorPresenter
@characterWidthsChanged() unless @batchingCharacterMeasurement
characterWidthsChanged: ->
@linesYardstick.clearCache()
@shouldUpdateHorizontalScrollState = true
@shouldUpdateVerticalScrollState = true
@shouldUpdateScrollbarsState = true