Merge goal ranges when merging selections

This commit is contained in:
Nathan Sobo
2013-04-05 12:15:21 -06:00
parent be009e87c2
commit bd58834e7d
2 changed files with 12 additions and 1 deletions

View File

@@ -748,11 +748,18 @@ describe "EditSession", ->
editSession.addSelectionBelow()
editSession.selectLeft()
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 37]]
[[4, 22], [4, 29]]
[[5, 22], [5, 28]]
]
# goal range from previous add selection is honored next time
editSession.addSelectionBelow()
expect(editSession.getSelectedBufferRanges()).toEqual [
[[3, 22], [3, 37]]
[[4, 22], [4, 29]]
[[5, 22], [5, 29]]
[[5, 22], [5, 30]] # select to end of line 5 because line 4's goal range was reset by line 3 previously
[[6, 22], [6, 28]]
]

View File

@@ -394,6 +394,10 @@ class Selection
merge: (otherSelection, options) ->
@setBufferRange(@getBufferRange().union(otherSelection.getBufferRange()), options)
if @goalBufferRange and otherSelection.goalBufferRange
@goalBufferRange = @goalBufferRange.union(otherSelection.goalBufferRange)
else if otherSelection.goalBufferRange
@goalBufferRange = otherSelection.goalBufferRange
otherSelection.destroy()
_.extend Selection.prototype, EventEmitter