diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index e5bd91b82..2fb732910 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -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]] diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 2846412d2..cef8da34c 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -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...)