mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Add EditSession.consolidateSelections()
This commit is contained in:
@@ -792,6 +792,20 @@ describe "EditSession", ->
|
||||
[[10, 0], [10, 0]]
|
||||
]
|
||||
|
||||
describe ".consolidateSelections()", ->
|
||||
it "destroys all selections but the most recent, returning true if any selections were destroyed", ->
|
||||
editSession.setSelectedBufferRange([[3, 16], [3, 21]])
|
||||
selection1 = editSession.getSelection()
|
||||
selection2 = editSession.addSelectionForBufferRange([[3, 25], [3, 34]])
|
||||
selection3 = editSession.addSelectionForBufferRange([[8, 4], [8, 10]])
|
||||
|
||||
expect(editSession.getSelections()).toEqual [selection1, selection2, selection3]
|
||||
expect(editSession.consolidateSelections()).toBeTruthy()
|
||||
expect(editSession.getSelections()).toEqual [selection3]
|
||||
expect(selection3.isEmpty()).toBeFalsy()
|
||||
expect(editSession.consolidateSelections()).toBeFalsy()
|
||||
expect(editSession.getSelections()).toEqual [selection3]
|
||||
|
||||
describe "when the cursor is moved while there is a selection", ->
|
||||
makeSelection = -> selection.setBufferRange [[1, 2], [1, 5]]
|
||||
|
||||
|
||||
@@ -626,13 +626,16 @@ class EditSession
|
||||
_.remove(@selections, selection)
|
||||
|
||||
clearSelections: ->
|
||||
lastSelection = @getLastSelection()
|
||||
for selection in @getSelections() when selection != lastSelection
|
||||
selection.destroy()
|
||||
lastSelection.clear()
|
||||
@consolidateSelections()
|
||||
@getSelection().clear()
|
||||
|
||||
clearAllSelections: ->
|
||||
selection.destroy() for selection in @getSelections()
|
||||
consolidateSelections: ->
|
||||
selections = @getSelections()
|
||||
if selections.length > 1
|
||||
selection.destroy() for selection in selections[0...-1]
|
||||
true
|
||||
else
|
||||
false
|
||||
|
||||
getSelections: -> new Array(@selections...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user