diff --git a/spec/text-editor-presenter-spec.coffee b/spec/text-editor-presenter-spec.coffee index ca4ab4ba4..43dc6ef3c 100644 --- a/spec/text-editor-presenter-spec.coffee +++ b/spec/text-editor-presenter-spec.coffee @@ -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} diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index 94831eac1..ea3bb76f8 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -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} diff --git a/src/text-editor-presenter.coffee b/src/text-editor-presenter.coffee index 91450ca57..ae9584204 100644 --- a/src/text-editor-presenter.coffee +++ b/src/text-editor-presenter.coffee @@ -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