mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
Move autoScrolling methods from cursor to editor
Scroll methods are now Editor.scrollTo(), Editor.scrollHorizontally() and Editor.scrollVertically() Editor.scrollTo() can only be called once per runloop
This commit is contained in:
@@ -137,43 +137,4 @@ class Cursor extends View
|
||||
@css(position)
|
||||
|
||||
if @editor.getCursors().length == 1 or @editor.screenPositionInBounds(screenPosition)
|
||||
@autoScroll(position)
|
||||
|
||||
autoScroll: (position) ->
|
||||
return if @editor._autoScrolling
|
||||
|
||||
@editor._autoScrolling = true
|
||||
_.defer =>
|
||||
@editor._autoScrolling = false
|
||||
@autoScrollVertically(position)
|
||||
@autoScrollHorizontally(position)
|
||||
|
||||
autoScrollVertically: (position) ->
|
||||
linesInView = @editor.scroller.height() / @editor.lineHeight
|
||||
maxScrollMargin = Math.floor((linesInView - 1) / 2)
|
||||
scrollMargin = Math.min(@editor.vScrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * @height()
|
||||
desiredTop = position.top - margin
|
||||
desiredBottom = position.top + @height() + margin
|
||||
|
||||
if desiredBottom > @editor.scroller.scrollBottom()
|
||||
@editor.scroller.scrollBottom(desiredBottom)
|
||||
else if desiredTop < @editor.scroller.scrollTop()
|
||||
@editor.scroller.scrollTop(desiredTop)
|
||||
|
||||
autoScrollHorizontally: (position) ->
|
||||
return if @editor.softWrap
|
||||
|
||||
charWidth = @editor.charWidth
|
||||
charsInView = @editor.scroller.width() / charWidth
|
||||
maxScrollMargin = Math.floor((charsInView - 1) / 2)
|
||||
scrollMargin = Math.min(@editor.hScrollMargin, maxScrollMargin)
|
||||
margin = scrollMargin * charWidth
|
||||
desiredRight = position.left + charWidth + margin
|
||||
desiredLeft = position.left - margin
|
||||
|
||||
if desiredRight > @editor.scroller.scrollRight()
|
||||
@editor.scroller.scrollRight(desiredRight)
|
||||
else if desiredLeft < @editor.scroller.scrollLeft()
|
||||
@editor.scroller.scrollLeft(desiredLeft)
|
||||
|
||||
@editor.scrollTo(position)
|
||||
|
||||
@@ -37,6 +37,7 @@ class Editor extends View
|
||||
autoIndent: null
|
||||
lineCache: null
|
||||
isFocused: false
|
||||
isScrolling: false
|
||||
|
||||
initialize: ({buffer}) ->
|
||||
requireStylesheet 'editor.css'
|
||||
@@ -328,8 +329,9 @@ class Editor extends View
|
||||
clipScreenPosition: (screenPosition, options={}) ->
|
||||
@renderer.clipScreenPosition(screenPosition, options)
|
||||
|
||||
pixelPositionForScreenPosition: ({row, column}) ->
|
||||
{ top: row * @lineHeight, left: column * @charWidth }
|
||||
pixelPositionForScreenPosition: (position) ->
|
||||
position = Point.fromObject(position)
|
||||
{ top: position.row * @lineHeight, left: position.column * @charWidth }
|
||||
|
||||
screenPositionFromPixelPosition: ({top, left}) ->
|
||||
screenPosition = new Point(Math.floor(top / @lineHeight), Math.floor(left / @charWidth))
|
||||
@@ -478,5 +480,41 @@ class Editor extends View
|
||||
getCurrentMode: ->
|
||||
@buffer.getMode()
|
||||
|
||||
scrollTo: (position) ->
|
||||
return if @isScrolling
|
||||
@isScrolling = true
|
||||
_.defer =>
|
||||
@isScrolling = false
|
||||
@scrollVertically(position)
|
||||
@scrollHorizontally(position)
|
||||
|
||||
scrollVertically: (position) ->
|
||||
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
|
||||
|
||||
if desiredBottom > @scroller.scrollBottom()
|
||||
@scroller.scrollBottom(desiredBottom)
|
||||
else if desiredTop < @scroller.scrollTop()
|
||||
@scroller.scrollTop(desiredTop)
|
||||
|
||||
scrollHorizontally: (position) ->
|
||||
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
|
||||
|
||||
if desiredRight > @scroller.scrollRight()
|
||||
@scroller.scrollRight(desiredRight)
|
||||
else if desiredLeft < @scroller.scrollLeft()
|
||||
@scroller.scrollLeft(desiredLeft)
|
||||
|
||||
logLines: ->
|
||||
@renderer.logLines()
|
||||
|
||||
Reference in New Issue
Block a user