mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Maintain selection directionality when merging selections with keyboard
This commit is contained in:
@@ -1077,6 +1077,7 @@ describe "Editor", ->
|
||||
editor.selectDown()
|
||||
expect(editor.compositeSelection.getSelections()).toEqual [selection1]
|
||||
expect(selection1.getScreenRange()).toEqual([[0, 9], [4, 25]])
|
||||
expect(selection1.isReversed()).toBeFalsy()
|
||||
expect(selection2.parent()).not.toExist()
|
||||
expect(selection3.parent()).not.toExist()
|
||||
|
||||
@@ -1088,6 +1089,7 @@ describe "Editor", ->
|
||||
editor.selectUp()
|
||||
expect(editor.compositeSelection.getSelections()).toEqual [selection1]
|
||||
expect(selection1.getScreenRange()).toEqual([[0, 0], [1, 20]])
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
expect(selection2.parent()).not.toExist()
|
||||
|
||||
it "merges selections when they intersect when moving left", ->
|
||||
@@ -1098,6 +1100,7 @@ describe "Editor", ->
|
||||
editor.selectLeft()
|
||||
expect(editor.compositeSelection.getSelections()).toEqual [selection1]
|
||||
expect(selection1.getScreenRange()).toEqual([[0, 8], [1, 20]])
|
||||
expect(selection1.isReversed()).toBeTruthy()
|
||||
expect(selection2.parent()).not.toExist()
|
||||
|
||||
it "merges selections when they intersect when moving right", ->
|
||||
@@ -1108,6 +1111,7 @@ describe "Editor", ->
|
||||
editor.selectRight()
|
||||
expect(editor.compositeSelection.getSelections()).toEqual [selection1]
|
||||
expect(selection1.getScreenRange()).toEqual([[0, 9], [1, 21]])
|
||||
expect(selection1.isReversed()).toBeFalsy()
|
||||
expect(selection2.parent()).not.toExist()
|
||||
|
||||
describe "cursor merging", ->
|
||||
|
||||
@@ -205,3 +205,12 @@ describe "Selection", ->
|
||||
editor.setCursorScreenPosition [0,2]
|
||||
selection.selectLine(1)
|
||||
expect(selection.getText()).toBe " var sort = function(items) {"
|
||||
|
||||
describe ".isReversed()", ->
|
||||
it "returns true if the cursor precedes the anchor", ->
|
||||
selection.cursor.setScreenPosition([0, 20])
|
||||
selection.selectToScreenPosition([0, 10])
|
||||
expect(selection.isReversed()).toBeTruthy()
|
||||
|
||||
selection.selectToScreenPosition([0, 25])
|
||||
expect(selection.isReversed()).toBeFalsy()
|
||||
|
||||
@@ -49,11 +49,11 @@ class CompositeSeleciton
|
||||
|
||||
selectLeft: ->
|
||||
selection.selectLeft() for selection in @getSelections()
|
||||
@mergeIntersectingSelections()
|
||||
@mergeIntersectingSelections reverse: true
|
||||
|
||||
selectUp: ->
|
||||
selection.selectUp() for selection in @getSelections()
|
||||
@mergeIntersectingSelections()
|
||||
@mergeIntersectingSelections reverse: true
|
||||
|
||||
selectDown: ->
|
||||
selection.selectDown() for selection in @getSelections()
|
||||
@@ -71,14 +71,14 @@ class CompositeSeleciton
|
||||
lastSelection: ->
|
||||
_.last(@selections)
|
||||
|
||||
mergeIntersectingSelections: ->
|
||||
mergeIntersectingSelections: (options) ->
|
||||
for selection in @getSelections()
|
||||
otherSelections = @getSelections()
|
||||
_.remove(otherSelections, selection)
|
||||
for otherSelection in otherSelections
|
||||
if selection.intersectsWith(otherSelection)
|
||||
selection.merge(otherSelection)
|
||||
@mergeIntersectingSelections()
|
||||
selection.merge(otherSelection, options)
|
||||
@mergeIntersectingSelections(options)
|
||||
return
|
||||
|
||||
modifySelectedText: (fn) ->
|
||||
|
||||
@@ -139,11 +139,14 @@ class Selection extends View
|
||||
isEmpty: ->
|
||||
@getBufferRange().isEmpty()
|
||||
|
||||
isReversed: ->
|
||||
@cursor.getBufferPosition().isLessThan(@anchorBufferPosition)
|
||||
|
||||
intersectsWith: (otherSelection) ->
|
||||
@getScreenRange().intersectsWith(otherSelection.getScreenRange())
|
||||
|
||||
merge: (otherSelection) ->
|
||||
@setScreenRange(@getScreenRange().union(otherSelection.getScreenRange()))
|
||||
merge: (otherSelection, options) ->
|
||||
@setScreenRange(@getScreenRange().union(otherSelection.getScreenRange()), options)
|
||||
otherSelection.remove()
|
||||
|
||||
remove: ->
|
||||
|
||||
Reference in New Issue
Block a user