mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Preserve original selection's range when adding selection's below
Just like the cursor tries to stay in its "goal column" when moving vertically, here we try to keep the same selection even when adding across shorter lines.
This commit is contained in:
@@ -585,7 +585,7 @@ class EditSession
|
||||
unless options.preserveFolds
|
||||
@destroyFoldsIntersectingBufferRange(@getMarkerBufferRange(marker))
|
||||
cursor = @addCursor(marker)
|
||||
selection = new Selection({editSession: this, marker, cursor})
|
||||
selection = new Selection(_.extend({editSession: this, marker, cursor}, options))
|
||||
@selections.push(selection)
|
||||
selectionBufferRange = selection.getBufferRange()
|
||||
@mergeIntersectingSelections()
|
||||
@@ -600,7 +600,7 @@ class EditSession
|
||||
addSelectionForBufferRange: (bufferRange, options={}) ->
|
||||
options = _.defaults({invalidationStrategy: 'never'}, options)
|
||||
marker = @markBufferRange(bufferRange, options)
|
||||
@addSelection(marker)
|
||||
@addSelection(marker, options)
|
||||
|
||||
setSelectedBufferRange: (bufferRange, options) ->
|
||||
@setSelectedBufferRanges([bufferRange], options)
|
||||
|
||||
@@ -5,10 +5,12 @@ _ = require 'underscore'
|
||||
module.exports =
|
||||
class Selection
|
||||
wordwise: false
|
||||
editSession: null
|
||||
initialScreenRange: null
|
||||
goalBufferRange: null
|
||||
needsAutoscroll: null
|
||||
|
||||
constructor: ({@cursor, @marker, @editSession}) ->
|
||||
constructor: ({@cursor, @marker, @editSession, @goalBufferRange}) ->
|
||||
@cursor.selection = this
|
||||
@editSession.observeMarker @marker, => @screenRangeChanged()
|
||||
@cursor.on 'destroyed.selection', =>
|
||||
@@ -149,10 +151,10 @@ class Selection
|
||||
@modifySelection => @cursor.moveToEndOfWord()
|
||||
|
||||
addSelectionBelow: ->
|
||||
range = @getBufferRange().copy()
|
||||
range = (@goalBufferRange ? @getBufferRange()).copy()
|
||||
range.start.row++
|
||||
range.end.row++
|
||||
@editSession.addSelectionForBufferRange(range)
|
||||
@editSession.addSelectionForBufferRange(range, goalBufferRange: range)
|
||||
|
||||
insertText: (text, options={}) ->
|
||||
oldBufferRange = @getBufferRange()
|
||||
|
||||
Reference in New Issue
Block a user