Move merging of intersecting selections into EditSession and the Selection model

This commit is contained in:
Nathan Sobo
2012-06-08 13:26:54 -06:00
parent 7eb01272ed
commit 31bd38dfcc
5 changed files with 35 additions and 26 deletions

View File

@@ -9,14 +9,19 @@ class Selection
anchor: null
constructor: ({@cursor, @editSession}) ->
@cursor.on 'change-screen-position', (e) =>
@cursor.on 'change-screen-position.selection', (e) =>
@trigger 'change-screen-range', @getScreenRange() unless e.bufferChanged
@cursor.on 'destroy', => @destroy()
@cursor.on 'destroy.selection', =>
@cursor = null
@destroy()
destroy: ->
@cursor.off()
if @cursor
@cursor.off('.selection')
@cursor.destroy()
@editSession.removeSelection(this)
@trigger 'destroy'
getScreenRange: ->
if @anchor
@@ -103,4 +108,11 @@ class Selection
@anchor = new Anchor(@editSession)
@anchor.setScreenPosition(@cursor.getScreenPosition())
intersectsWith: (otherSelection) ->
@getScreenRange().intersectsWith(otherSelection.getScreenRange())
merge: (otherSelection, options) ->
@setScreenRange(@getScreenRange().union(otherSelection.getScreenRange()), options)
otherSelection.destroy()
_.extend Selection.prototype, EventEmitter