Don't autoscroll to bottom of buffer on selectAll

This commit is contained in:
Nathan Sobo 2012-11-07 16:01:10 -07:00
parent d1d3b45474
commit 19c8a39fc8
4 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -154,7 +154,7 @@ class Selection
@modifySelection => @cursor.moveToBottom()
selectAll: ->
@setBufferRange(@editSession.buffer.getRange())
@setBufferRange(@editSession.buffer.getRange(), autoscroll: false)
selectToBeginningOfLine: ->
@modifySelection => @cursor.moveToBeginningOfLine()