🎨 Move pixel-related code to LinesYardstick

* 🔥 Remove useless 'scoped char width' methods
This commit is contained in:
Antonio Scandurra
2015-10-01 11:03:25 +02:00
parent 58219a243e
commit 243dea1a1c
5 changed files with 36 additions and 30 deletions

View File

@@ -56,3 +56,18 @@ class FakeLinesYardstick
column += charLength
{top, left}
pixelRectForScreenRange: (screenRange) ->
lineHeight = @model.getLineHeightInPixels()
if screenRange.end.row > screenRange.start.row
top = @pixelPositionForScreenPosition(screenRange.start).top
left = 0
height = (screenRange.end.row - screenRange.start.row + 1) * lineHeight
width = @presenter.getScrollWidth()
else
{top, left} = @pixelPositionForScreenPosition(screenRange.start, false)
height = lineHeight
width = @pixelPositionForScreenPosition(screenRange.end, false).left - left
{top, left, width, height}

View File

@@ -165,3 +165,18 @@ class LinesYardstick
@rangeForMeasurement.getBoundingClientRect().left
position - lineNode.getBoundingClientRect().left
pixelRectForScreenRange: (screenRange) ->
lineHeight = @model.getLineHeightInPixels()
if screenRange.end.row > screenRange.start.row
top = @pixelPositionForScreenPosition(screenRange.start).top
left = 0
height = (screenRange.end.row - screenRange.start.row + 1) * lineHeight
width = @presenter.getScrollWidth()
else
{top, left} = @pixelPositionForScreenPosition(screenRange.start, false)
height = lineHeight
width = @pixelPositionForScreenPosition(screenRange.end, false).left - left
{top, left, width, height}

View File

@@ -418,21 +418,13 @@ class TextEditorComponent
@presenter.getVisibleRowRange()
pixelPositionForScreenPosition: (screenPosition) ->
position = @presenter.pixelPositionForScreenPosition(screenPosition)
position.top += @presenter.getScrollTop()
position.left += @presenter.getScrollLeft()
position
@linesYardstick.pixelPositionForScreenPosition(screenPosition)
screenPositionForPixelPosition: (pixelPosition) ->
@linesYardstick.screenPositionForPixelPosition(pixelPosition)
pixelRectForScreenRange: (screenRange) ->
rect = @presenter.pixelRectForScreenRange(screenRange)
rect.top += @presenter.getScrollTop()
rect.bottom += @presenter.getScrollTop()
rect.left += @presenter.getScrollLeft()
rect.right += @presenter.getScrollLeft()
rect
@linesYardstick.pixelRectForScreenRange(screenRange)
pixelRangeForScreenRange: (screenRange, clip=true) ->
{start, end} = Range.fromObject(screenRange)

View File

@@ -1133,17 +1133,10 @@ class TextEditorPresenter
@hasPixelRectRequirements() and @boundingClientRect? and @windowWidth and @windowHeight
pixelRectForScreenRange: (screenRange) ->
if screenRange.end.row > screenRange.start.row
top = @pixelPositionForScreenPosition(screenRange.start).top
left = 0
height = (screenRange.end.row - screenRange.start.row + 1) * @lineHeight
width = @scrollWidth
else
{top, left} = @pixelPositionForScreenPosition(screenRange.start, false)
height = @lineHeight
width = @pixelPositionForScreenPosition(screenRange.end, false).left - left
{top, left, width, height}
rect = @linesYardstick.pixelRectForScreenRange(screenRange)
rect.top -= @getScrollTop()
rect.left -= @getScrollLeft()
rect
observeDecoration: (decoration) ->
decorationDisposables = new CompositeDisposable

View File

@@ -2966,15 +2966,6 @@ class TextEditor extends Model
getLineHeightInPixels: -> @displayBuffer.getLineHeightInPixels()
setLineHeightInPixels: (lineHeightInPixels) -> @displayBuffer.setLineHeightInPixels(lineHeightInPixels)
batchCharacterMeasurement: (fn) -> @displayBuffer.batchCharacterMeasurement(fn)
getScopedCharWidth: (scopeNames, char) -> @displayBuffer.getScopedCharWidth(scopeNames, char)
setScopedCharWidth: (scopeNames, char, width) -> @displayBuffer.setScopedCharWidth(scopeNames, char, width)
getScopedCharWidths: (scopeNames) -> @displayBuffer.getScopedCharWidths(scopeNames)
clearScopedCharWidths: -> @displayBuffer.clearScopedCharWidths()
getDefaultCharWidth: -> @displayBuffer.getDefaultCharWidth()
setDefaultCharWidth: (defaultCharWidth) -> @displayBuffer.setDefaultCharWidth(defaultCharWidth)