diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index c6870c7f7..3337d526b 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -396,6 +396,20 @@ describe "EditSession", -> buffer.insert([8, 0], '...') expect(cursorMovedHandler).not.toHaveBeenCalled() + describe "addCursorAtScreenPosition(screenPosition)", -> + describe "when a cursor already exists at the position", -> + it "returns the existing cursor", -> + cursor1 = editSession.addCursorAtScreenPosition([0,2]) + cursor2 = editSession.addCursorAtScreenPosition([0,2]) + expect(cursor2.marker).toBe cursor1.marker + + describe "addCursorAtBufferPosition(bufferPosition)", -> + describe "when a cursor already exists at the position", -> + it "returns the existing cursor", -> + cursor1 = editSession.addCursorAtBufferPosition([1,4]) + cursor2 = editSession.addCursorAtBufferPosition([1,4]) + expect(cursor2.marker).toBe cursor1.marker + describe "selection", -> selection = null diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index f1ddfa232..e14baa16a 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -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)