Revert "Maintain scroll history"

This reverts commit 2e6bb53303.
This commit is contained in:
Antonio Scandurra
2015-09-25 10:31:48 +02:00
parent 2e6bb53303
commit d65b5d1793
4 changed files with 76 additions and 99 deletions

View File

@@ -317,7 +317,7 @@ class TextEditorComponent
pendingScrollTop = @pendingScrollTop
@pendingScrollTop = null
@presenter.setScrollTop(pendingScrollTop)
@presenter.commitScrollQueue()
@presenter.commitPendingScrollTopPosition()
onHorizontalScroll: (scrollLeft) =>
return if @updateRequested or scrollLeft is @presenter.getScrollLeft()
@@ -327,7 +327,7 @@ class TextEditorComponent
unless animationFramePending
@requestAnimationFrame =>
@presenter.setScrollLeft(@pendingScrollLeft)
@presenter.commitScrollQueue()
@presenter.commitPendingScrollLeftPosition()
@pendingScrollLeft = null
onMouseWheel: (event) =>
@@ -613,11 +613,11 @@ class TextEditorComponent
if mouseYDelta?
@presenter.setScrollTop(@presenter.getScrollTop() + yDirection * scaleScrollDelta(mouseYDelta))
@presenter.commitScrollQueue()
@presenter.commitPendingScrollTopPosition()
if mouseXDelta?
@presenter.setScrollLeft(@presenter.getScrollLeft() + xDirection * scaleScrollDelta(mouseXDelta))
@presenter.commitScrollQueue()
@presenter.commitPendingScrollLeftPosition()
scaleScrollDelta = (scrollDelta) ->
Math.pow(scrollDelta / 2, 3) / 280

View File

@@ -3,23 +3,6 @@
_ = require 'underscore-plus'
Decoration = require './decoration'
class ScrollQueue
constructor: ->
@queue = []
@committing = false
enqueue: (scrollAction) ->
if @committing
@queue.unshift(scrollAction)
else
@queue.push(scrollAction)
commit: ->
@committing = true
while scrollAction = @queue.shift()
scrollAction()
@committing = false
module.exports =
class TextEditorPresenter
toggleCursorBlinkHandle: null
@@ -39,7 +22,6 @@ class TextEditorPresenter
@measuredVerticalScrollbarWidth = verticalScrollbarWidth
@gutterWidth ?= 0
@tileSize ?= 6
@scrollQueue = new ScrollQueue
@disposables = new CompositeDisposable
@emitter = new Emitter
@@ -834,7 +816,7 @@ class TextEditorPresenter
setScrollTop: (scrollTop) ->
return unless scrollTop?
@scrollQueue.enqueue => @commitScrollTop(scrollTop)
@pendingScrollTop = scrollTop
@shouldUpdateVerticalScrollState = true
@shouldUpdateHiddenInputState = true
@@ -874,7 +856,7 @@ class TextEditorPresenter
setScrollLeft: (scrollLeft) ->
return unless scrollLeft?
@scrollQueue.enqueue => @commitScrollLeft(scrollLeft)
@pendingScrollLeft = scrollLeft
@shouldUpdateHorizontalScrollState = true
@shouldUpdateHiddenInputState = true
@@ -1491,54 +1473,7 @@ class TextEditorPresenter
@emitDidUpdateState()
didChangeScrollPosition: (position) ->
@scrollQueue.enqueue =>
{screenRange, options} = position
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
top += @getScrollTop()
bottom += @getScrollTop()
left += @getScrollLeft()
right += @getScrollLeft()
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 options?.reversed ? true
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
else
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
@pendingScrollLogicalPosition = position
@shouldUpdateCursorsState = true
@shouldUpdateCustomGutterDecorationState = true
@@ -1565,10 +1500,63 @@ class TextEditorPresenter
getHorizontalScrollbarHeight: ->
@horizontalScrollbarHeight
commitScrollLeft: (scrollLeft) ->
return unless scrollLeft?
commitPendingLogicalScrollPosition: ->
return unless @pendingScrollLogicalPosition?
scrollLeft = @constrainScrollLeft(scrollLeft)
{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
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 options?.reversed ? true
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
else
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
@pendingScrollLogicalPosition = null
commitPendingScrollLeftPosition: ->
return unless @pendingScrollLeft?
scrollLeft = @constrainScrollLeft(@pendingScrollLeft)
if scrollLeft isnt @scrollLeft and not Number.isNaN(scrollLeft)
@realScrollLeft = scrollLeft
@scrollLeft = Math.round(scrollLeft)
@@ -1579,10 +1567,10 @@ class TextEditorPresenter
@pendingScrollLeft = null
commitScrollTop: (scrollTop) ->
return unless scrollTop?
commitPendingScrollTopPosition: ->
return unless @pendingScrollTop?
scrollTop = @constrainScrollTop(scrollTop)
scrollTop = @constrainScrollTop(@pendingScrollTop)
if scrollTop isnt @scrollTop and not Number.isNaN(scrollTop)
@realScrollTop = scrollTop
@scrollTop = Math.round(scrollTop)
@@ -1592,8 +1580,10 @@ class TextEditorPresenter
@didStartScrolling()
@emitter.emit 'did-change-scroll-top', @scrollTop
@pendingScrollTop = null
restoreScrollPosition: ->
return unless @hasPixelPositionRequirements()
return if @hasRestoredScrollPosition or not @hasPixelPositionRequirements()
@setScrollTop(@scrollRow * @lineHeight) if @scrollRow?
@setScrollLeft(@scrollColumn * @baseCharacterWidth) if @scrollColumn?
@@ -1601,11 +1591,10 @@ class TextEditorPresenter
@hasRestoredScrollPosition = true
updateScrollPosition: ->
@restoreScrollPosition() unless @hasRestoredScrollPosition
@commitScrollQueue()
commitScrollQueue: ->
@scrollQueue.commit()
@restoreScrollPosition()
@commitPendingLogicalScrollPosition()
@commitPendingScrollLeftPosition()
@commitPendingScrollTopPosition()
onDidChangeScrollTop: (callback) ->
@emitter.on 'did-change-scroll-top', callback