Return existing selections from addSelection()

Previously if a selection was added and then merged
away the selection-added event would still fire even
though the selection was already destroyed.

Now the existing selection that intersects with the
range is returned when the merge destroys the new selection.

Closes #374
This commit is contained in:
Kevin Sawicki
2013-03-27 17:56:25 -04:00
parent b6334483c9
commit 1d84274973
2 changed files with 22 additions and 2 deletions

View File

@@ -584,9 +584,15 @@ class EditSession
cursor = @addCursor(marker)
selection = new Selection({editSession: this, marker, cursor})
@selections.push(selection)
selectionBufferRange = selection.getBufferRange()
@mergeIntersectingSelections()
@trigger 'selection-added', selection
selection
if selection.destroyed
for selection in @getSelections()
if selection.intersectsBufferRange(selectionBufferRange)
return selection
else
@trigger 'selection-added', selection
selection
addSelectionForBufferRange: (bufferRange, options={}) ->
options = _.defaults({invalidationStrategy: 'never'}, options)