mirror of
https://github.com/atom/atom.git
synced 2026-01-28 16:28:09 -05:00
💚
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1046,6 +1046,8 @@ class TextEditorPresenter
|
||||
@characterWidthsChanged() unless @batchingCharacterMeasurement
|
||||
|
||||
characterWidthsChanged: ->
|
||||
@linesYardstick.clearCache()
|
||||
|
||||
@shouldUpdateHorizontalScrollState = true
|
||||
@shouldUpdateVerticalScrollState = true
|
||||
@shouldUpdateScrollbarsState = true
|
||||
|
||||
Reference in New Issue
Block a user