Make it more obvious that Editor's scroll methods take pixelPositions

This commit is contained in:
Corey Johnson 2012-04-04 11:19:17 -07:00
parent 2e9bef04a9
commit 6ad50b379f
2 changed files with 12 additions and 12 deletions

View File

@ -133,8 +133,8 @@ class Cursor extends View
updateAppearance: ->
screenPosition = @getScreenPosition()
position = @editor.pixelPositionForScreenPosition(screenPosition)
@css(position)
pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition)
@css(pixelPosition)
if this == _.last(@editor.getCursors())
@editor.scrollTo(position)
@editor.scrollTo(pixelPosition)

View File

@ -481,33 +481,33 @@ class Editor extends View
getCurrentMode: ->
@buffer.getMode()
scrollTo: (position) ->
scrollTo: (pixelPosition) ->
_.defer =>
@scrollVertically(position)
@scrollHorizontally(position)
@scrollVertically(pixelPosition)
@scrollHorizontally(pixelPosition)
scrollVertically: (position) ->
scrollVertically: (pixelPosition) ->
linesInView = @scroller.height() / @lineHeight
maxScrollMargin = Math.floor((linesInView - 1) / 2)
scrollMargin = Math.min(@vScrollMargin, maxScrollMargin)
margin = scrollMargin * @lineHeight
desiredTop = position.top - margin
desiredBottom = position.top + @lineHeight + margin
desiredTop = pixelPosition.top - margin
desiredBottom = pixelPosition.top + @lineHeight + margin
if desiredBottom > @scroller.scrollBottom()
@scroller.scrollBottom(desiredBottom)
else if desiredTop < @scroller.scrollTop()
@scroller.scrollTop(desiredTop)
scrollHorizontally: (position) ->
scrollHorizontally: (pixelPosition) ->
return if @softWrap
charsInView = @scroller.width() / @charWidth
maxScrollMargin = Math.floor((charsInView - 1) / 2)
scrollMargin = Math.min(@hScrollMargin, maxScrollMargin)
margin = scrollMargin * @charWidth
desiredRight = position.left + @charWidth + margin
desiredLeft = position.left - margin
desiredRight = pixelPosition.left + @charWidth + margin
desiredLeft = pixelPosition.left - margin
if desiredRight > @scroller.scrollRight()
@scroller.scrollRight(desiredRight)