💚 Fix TextEditorPresenter specs

...so that they play nicely with LinesYardstick
This commit is contained in:
Antonio Scandurra
2015-09-16 11:33:51 +02:00
parent 29846d0a51
commit 2750a384ac
2 changed files with 72 additions and 55 deletions

View File

@@ -38,6 +38,8 @@ class TextEditorPresenter
@startBlinkingCursors() if @focused
@updating = false
setLinesYardstick: (@linesYardstick) ->
destroy: ->
@disposables.dispose()
@@ -1057,42 +1059,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) ->
pixelPosition =
@linesYardstick.pixelPositionForScreenPosition(screenPosition, clip)
pixelPosition.top -= @scrollTop
pixelPosition.left -= @scrollLeft
pixelPosition
hasPixelRectRequirements: ->
@hasPixelPositionRequirements() and @scrollWidth?