mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -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:
@@ -720,6 +720,18 @@ describe "EditSession", ->
|
||||
[[4, 25], [4, 29]]
|
||||
]
|
||||
|
||||
it "honors the original selection's region when adding across shorter lines", ->
|
||||
editSession.setSelectedBufferRange([[3, 22], [3, 38]])
|
||||
editSession.addSelectionBelow()
|
||||
editSession.addSelectionBelow()
|
||||
editSession.addSelectionBelow()
|
||||
expect(editSession.getSelectedBufferRanges()).toEqual [
|
||||
[[3, 22], [3, 38]]
|
||||
[[4, 22], [4, 29]]
|
||||
[[5, 22], [5, 30]]
|
||||
[[6, 22], [6, 38]]
|
||||
]
|
||||
|
||||
describe "when the cursor is moved while there is a selection", ->
|
||||
makeSelection = -> selection.setBufferRange [[1, 2], [1, 5]]
|
||||
|
||||
|
||||
@@ -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