diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 8ec68db22..6445d192a 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -876,6 +876,16 @@ describe "Editor", -> expect(editor.getSelectionViews().length).toBe 1 expect(editor.find('.selection').length).toBe 3 + describe "when the selection is created with the selectAll event", -> + it "does not scroll to the end of the buffer", -> + editor.height(150) + editor.selectAll() + expect(editor.scrollTop()).toBe 0 + + # does auto-scroll when the selection is cleared + editor.moveCursorDown() + expect(editor.scrollTop()).toBeGreaterThan(0) + describe "cursor rendering", -> describe "when the cursor moves", -> charWidth = null diff --git a/src/app/anchor.coffee b/src/app/anchor.coffee index 79585658d..3e1790910 100644 --- a/src/app/anchor.coffee +++ b/src/app/anchor.coffee @@ -66,12 +66,12 @@ class Anchor Object.freeze @bufferPosition unless @screenPosition.isEqual(previousScreenPosition) - @trigger 'change-screen-position', @screenPosition, bufferChange: options.bufferChange + @trigger 'change-screen-position', @screenPosition, bufferChange: options.bufferChange, autoscroll: options.autoscroll refreshScreenPosition: (options={}) -> return unless @editSession screenPosition = @editSession.screenPositionForBufferPosition(@bufferPosition, options) - @setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false) + @setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false, autoscroll: options.autoscroll) destroy: -> @buffer.removeAnchor(this) diff --git a/src/app/cursor-view.coffee b/src/app/cursor-view.coffee index 6248b3ce9..3b4deb083 100644 --- a/src/app/cursor-view.coffee +++ b/src/app/cursor-view.coffee @@ -13,8 +13,8 @@ class CursorView extends View visible: true initialize: (@cursor, @editor) -> - @cursor.on 'change-screen-position.cursor-view', (screenPosition, { bufferChange }) => - @updateAppearance() + @cursor.on 'change-screen-position.cursor-view', (screenPosition, { bufferChange, autoscroll }) => + @updateAppearance({autoscroll}) @removeIdleClassTemporarily() unless bufferChange @trigger 'cursor-move', {bufferChange} @@ -31,23 +31,30 @@ class CursorView extends View @cursor.off('.cursor-view') super - updateAppearance: -> + updateAppearance: (options={}) -> screenPosition = @getScreenPosition() - pixelPosition = @editor.pixelPositionForScreenPosition(screenPosition) + pixelPosition = @getPixelPosition() @css(pixelPosition) if @cursor == @editor.getLastCursor() - @editor.scrollTo(pixelPosition) + @autoscroll() if options.autoscroll ? true @editor.hiddenInput.css(pixelPosition) @setVisible(@cursor.isVisible() and not @editor.isFoldedAtScreenRow(screenPosition.row)) + getPixelPosition: -> + @editor.pixelPositionForScreenPosition(@getScreenPosition()) + + autoscroll: -> + @editor.scrollTo(@getPixelPosition()) + setVisible: (visible) -> return if visible == @visible @visible = visible if @visible @show() + @autoscroll() else @hide() diff --git a/src/app/selection.coffee b/src/app/selection.coffee index 17066e120..bbe313050 100644 --- a/src/app/selection.coffee +++ b/src/app/selection.coffee @@ -154,7 +154,7 @@ class Selection @modifySelection => @cursor.moveToBottom() selectAll: -> - @setBufferRange(@editSession.buffer.getRange()) + @setBufferRange(@editSession.buffer.getRange(), autoscroll: false) selectToBeginningOfLine: -> @modifySelection => @cursor.moveToBeginningOfLine()