This commit is contained in:
Antonio Scandurra
2015-09-22 17:30:51 +02:00
parent b5a59017d5
commit 68e2d7e7e4
3 changed files with 29 additions and 20 deletions

View File

@@ -483,7 +483,7 @@ fdescribe "TextEditorPresenter", ->
describe ".hiddenInput", ->
describe ".top/.left", ->
fffit "is positioned over the last cursor it is in view and the editor is focused", ->
it "is positioned over the last cursor it is in view and the editor is focused", ->
editor.setCursorBufferPosition([3, 6])
presenter = buildPresenter(focused: false, explicitHeight: 50, contentFrameWidth: 300, horizontalScrollbarHeight: 0, verticalScrollbarWidth: 0)
expectValues presenter.getState().hiddenInput, {top: 0, left: 0}

View File

@@ -380,6 +380,11 @@ class DisplayBuffer extends Model
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))
scrollEvent = {screenRange, options}

View File

@@ -1477,39 +1477,43 @@ class TextEditorPresenter
{screenRange, options} = @pendingScrollLogicalPosition
console.log screenRange.start.toString()
console.log screenRange.end.toString()
# console.log screenRange.start.toString()
{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
if global.enableLogs
console.log "====== presenter ======"
console.log "Client Height: #{@getClientHeight()}"
console.log "#{desiredScrollTop}/#{desiredScrollBottom}"
console.log "#{top}/#{bottom}"
console.log "#{@getScrollTop()}/#{@getScrollBottom()}"
console.log "======================="
if options?.reversed ? true
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if bottom > @getScrollBottom()
@setScrollBottom(bottom)
if top < @getScrollTop()
@setScrollTop(top)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
if right > @getScrollRight()
@setScrollRight(right)
if left < @getScrollLeft()
@setScrollLeft(left)
else
if desiredScrollTop < @getScrollTop()
@setScrollTop(desiredScrollTop)
if desiredScrollBottom > @getScrollBottom()
@setScrollBottom(desiredScrollBottom)
if top < @getScrollTop()
@setScrollTop(top)
if bottom > @getScrollBottom()
@setScrollBottom(bottom)
if desiredScrollLeft < @getScrollLeft()
@setScrollLeft(desiredScrollLeft)
if desiredScrollRight > @getScrollRight()
@setScrollRight(desiredScrollRight)
if left < @getScrollLeft()
@setScrollLeft(left)
if right > @getScrollRight()
@setScrollRight(right)
@pendingScrollLogicalPosition = null