mirror of
https://github.com/atom/atom.git
synced 2026-01-25 14:59:03 -05:00
Move scroll margin into TextEditorPresenter
This commit is contained in:
@@ -362,35 +362,12 @@ class DisplayBuffer extends Model
|
||||
{start, end} = selection.getScreenRange()
|
||||
@intersectsVisibleRowRange(start.row, end.row + 1)
|
||||
|
||||
scrollToScreenRangeLogical: (screenRange, options) ->
|
||||
top = screenRange.start.row
|
||||
left = screenRange.start.column
|
||||
bottom = screenRange.end.row
|
||||
right = screenRange.end.column
|
||||
|
||||
if options?.center
|
||||
center = (top + bottom) / 2
|
||||
top = center - @getLogicalHeight() / 2
|
||||
bottom = center + @getLogicalHeight() / 2
|
||||
else
|
||||
top -= @getVerticalScrollMargin()
|
||||
bottom += @getVerticalScrollMargin()
|
||||
|
||||
left -= @getHorizontalScrollMargin()
|
||||
right += @getHorizontalScrollMargin()
|
||||
|
||||
top = Math.max(0, Math.min(@getLineCount() - 1, top))
|
||||
bottom = Math.max(0, Math.min(@getLineCount() - 1, bottom))
|
||||
left = Math.max(0, left)
|
||||
right = Math.max(0, right)
|
||||
|
||||
screenRange = new Range(new Point(top, left), new Point(bottom, right))
|
||||
|
||||
logicalScrollToScreenRange: (screenRange, options) ->
|
||||
scrollEvent = {screenRange, options}
|
||||
@emitter.emit "did-change-scroll-position", scrollEvent
|
||||
|
||||
scrollToScreenRange: (screenRange, options) ->
|
||||
@scrollToScreenRangeLogical(screenRange, options)
|
||||
@logicalScrollToScreenRange(screenRange, options)
|
||||
|
||||
verticalScrollMarginInPixels = @getVerticalScrollMarginInPixels()
|
||||
horizontalScrollMarginInPixels = @getHorizontalScrollMarginInPixels()
|
||||
@@ -414,9 +391,10 @@ class DisplayBuffer extends Model
|
||||
|
||||
if global.enableLogs
|
||||
console.log "====== DB ======"
|
||||
console.log "Client Height: #{@getClientHeight()}"
|
||||
console.log "#{desiredScrollTop}/#{desiredScrollBottom}"
|
||||
console.log "#{@getScrollTop()}/#{@getScrollBottom()}"
|
||||
console.log "Screen Range: #{screenRange.toString()}"
|
||||
console.log "Client Width: #{@getClientWidth()}"
|
||||
console.log "#{desiredScrollLeft}/#{desiredScrollRight}"
|
||||
console.log "#{@getScrollLeft()}/#{@getScrollRight()}"
|
||||
console.log "================"
|
||||
|
||||
if options?.reversed ? true
|
||||
|
||||
@@ -1472,40 +1472,69 @@ class TextEditorPresenter
|
||||
|
||||
@emitDidUpdateState()
|
||||
|
||||
getVerticalScrollMarginInPixels: ->
|
||||
@model.getVerticalScrollMargin() * @lineHeight
|
||||
|
||||
getHorizontalScrollMarginInPixels: ->
|
||||
@model.getHorizontalScrollMargin() * @baseCharacterWidth
|
||||
|
||||
updateScrollPosition: ->
|
||||
return unless @pendingScrollLogicalPosition?
|
||||
|
||||
{screenRange, options} = @pendingScrollLogicalPosition
|
||||
|
||||
verticalScrollMarginInPixels = @getVerticalScrollMarginInPixels()
|
||||
horizontalScrollMarginInPixels = @getHorizontalScrollMarginInPixels()
|
||||
|
||||
{top, left} = @pixelRectForScreenRange(new Range(screenRange.start, screenRange.start))
|
||||
{top: endTop, left: endLeft, height: endHeight} = @pixelRectForScreenRange(new Range(screenRange.end, screenRange.end))
|
||||
bottom = endTop + endHeight
|
||||
right = endLeft
|
||||
|
||||
left += @scrollLeft
|
||||
right += @scrollLeft
|
||||
top += @scrollTop
|
||||
bottom += @scrollTop
|
||||
left += @scrollLeft
|
||||
right += @scrollLeft
|
||||
|
||||
if options?.center
|
||||
desiredScrollCenter = (top + bottom) / 2
|
||||
unless @getScrollTop() < desiredScrollCenter < @getScrollBottom()
|
||||
desiredScrollTop = desiredScrollCenter - @getClientHeight() / 2
|
||||
desiredScrollBottom = desiredScrollCenter + @getClientHeight() / 2
|
||||
else
|
||||
desiredScrollTop = top - verticalScrollMarginInPixels
|
||||
desiredScrollBottom = bottom + verticalScrollMarginInPixels
|
||||
|
||||
desiredScrollLeft = left - horizontalScrollMarginInPixels
|
||||
desiredScrollRight = right + horizontalScrollMarginInPixels
|
||||
|
||||
if global.enableLogs
|
||||
console.log "====== DB ======"
|
||||
console.log "Screen Range: #{screenRange.toString()}"
|
||||
console.log "Client Width: #{@getClientWidth()}"
|
||||
console.log "#{desiredScrollLeft}/#{desiredScrollRight}"
|
||||
console.log "#{@getScrollLeft()}/#{@getScrollRight()}"
|
||||
console.log "================"
|
||||
|
||||
if options?.reversed ? true
|
||||
if bottom > @getScrollBottom()
|
||||
@setScrollBottom(bottom)
|
||||
if top < @getScrollTop()
|
||||
@setScrollTop(top)
|
||||
if desiredScrollBottom > @getScrollBottom()
|
||||
@setScrollBottom(desiredScrollBottom)
|
||||
if desiredScrollTop < @getScrollTop()
|
||||
@setScrollTop(desiredScrollTop)
|
||||
|
||||
if right > @getScrollRight()
|
||||
@setScrollRight(right)
|
||||
if left < @getScrollLeft()
|
||||
@setScrollLeft(left)
|
||||
if desiredScrollRight > @getScrollRight()
|
||||
@setScrollRight(desiredScrollRight)
|
||||
if desiredScrollLeft < @getScrollLeft()
|
||||
@setScrollLeft(desiredScrollLeft)
|
||||
else
|
||||
if top < @getScrollTop()
|
||||
@setScrollTop(top)
|
||||
if bottom > @getScrollBottom()
|
||||
@setScrollBottom(bottom)
|
||||
if desiredScrollTop < @getScrollTop()
|
||||
@setScrollTop(desiredScrollTop)
|
||||
if desiredScrollBottom > @getScrollBottom()
|
||||
@setScrollBottom(desiredScrollBottom)
|
||||
|
||||
if left < @getScrollLeft()
|
||||
@setScrollLeft(left)
|
||||
if right > @getScrollRight()
|
||||
@setScrollRight(right)
|
||||
if desiredScrollLeft < @getScrollLeft()
|
||||
@setScrollLeft(desiredScrollLeft)
|
||||
if desiredScrollRight > @getScrollRight()
|
||||
@setScrollRight(desiredScrollRight)
|
||||
|
||||
@pendingScrollLogicalPosition = null
|
||||
|
||||
Reference in New Issue
Block a user