Merge pull request #3440 from atom/ns-exclusive-selection-intersection

Don’t merge adjacent non-empty selections
This commit is contained in:
Nathan Sobo
2014-09-03 09:24:05 -06:00
4 changed files with 14 additions and 7 deletions

View File

@@ -56,7 +56,7 @@
"serializable": "^1",
"space-pen": "3.4.6",
"temp": "0.7.0",
"text-buffer": "^3.0.4",
"text-buffer": "^3.1.0",
"theorist": "^1.0.2",
"underscore-plus": "^1.5.1",
"vm-compatibility-layer": "0.1.0"

View File

@@ -901,14 +901,13 @@ describe "Editor", ->
[selection1, selection2] = editor.getSelections()
editor.selectUp()
expect(editor.getSelections().length).toBe 1
expect(editor.getSelections()).toEqual [selection1]
expect(selection1.getScreenRange()).toEqual([[0, 0], [1, 20]])
expect(selection1.isReversed()).toBeTruthy()
it "merges selections when they intersect when moving left", ->
editor.setSelectedBufferRanges([[[0,9], [0,13]], [[0,14], [1,20]]], reversed: true)
editor.setSelectedBufferRanges([[[0,9], [0,13]], [[0,13], [1,20]]], reversed: true)
[selection1, selection2] = editor.getSelections()
editor.selectLeft()
@@ -917,7 +916,7 @@ describe "Editor", ->
expect(selection1.isReversed()).toBeTruthy()
it "merges selections when they intersect when moving right", ->
editor.setSelectedBufferRanges([[[0,9], [0,13]], [[0,14], [1,20]]])
editor.setSelectedBufferRanges([[[0,9], [0,14]], [[0,14], [1,20]]])
[selection1, selection2] = editor.getSelections()
editor.selectRight()
@@ -1242,6 +1241,10 @@ describe "Editor", ->
editor.setSelectedBufferRanges([[[2, 2], [3, 3]], [[3, 0], [5, 5]]])
expect(editor.getSelectedBufferRanges()).toEqual [[[2, 2], [5, 5]]]
it "does not merge non-empty adjacent selections", ->
editor.setSelectedBufferRanges([[[2, 2], [3, 3]], [[3, 3], [5, 5]]])
expect(editor.getSelectedBufferRanges()).toEqual [[[2, 2], [3, 3]], [[3, 3], [5, 5]]]
it "recyles existing selection instances", ->
selection = editor.getLastSelection()
editor.setSelectedBufferRanges([[[2, 2], [3, 3]], [[4, 4], [5, 5]]])

View File

@@ -2201,7 +2201,11 @@ class Editor extends Model
@suppressSelectionMerging = false
reducer = (disjointSelections, selection) ->
intersectingSelection = _.find(disjointSelections, (s) -> s.intersectsWith(selection))
intersectingSelection = _.find disjointSelections, (otherSelection) ->
exclusive = not selection.isEmpty() and not otherSelection.isEmpty()
intersects = otherSelection.intersectsWith(selection, exclusive)
intersects
if intersectingSelection?
intersectingSelection.merge(selection, options)
disjointSelections

View File

@@ -629,8 +629,8 @@ class Selection extends Model
# * `otherSelection` A {Selection} to check against.
#
# Returns a {Boolean}
intersectsWith: (otherSelection) ->
@getBufferRange().intersectsWith(otherSelection.getBufferRange())
intersectsWith: (otherSelection, exclusive) ->
@getBufferRange().intersectsWith(otherSelection.getBufferRange(), exclusive)
# Public: Combines the given selection into this selection and then destroys
# the given selection.