Add Editor::onDidAdd/RemoveSelection

Also update EditorComponent to use the new ::onDidAddSelection method.
This commit is contained in:
Nathan Sobo
2014-09-04 09:59:08 -06:00
committed by Ben Ogle
parent 3e77b9b7c0
commit 651eb78315
2 changed files with 17 additions and 6 deletions

View File

@@ -33,7 +33,6 @@ EditorComponent = React.createClass
updateRequestedWhilePaused: false
cursorMoved: false
selectionChanged: false
selectionAdded: false
scrollingVertically: false
mouseWheelScreenRow: null
mouseWheelScreenRowClearDelay: 150
@@ -347,8 +346,7 @@ EditorComponent = React.createClass
{editor} = @props
@subscribe editor, 'screen-lines-changed', @onScreenLinesChanged
@subscribe editor.onDidAddCursor(@onCursorAdded)
@subscribe editor, 'selection-removed selection-screen-range-changed', @onSelectionChanged
@subscribe editor, 'selection-added', @onSelectionAdded
@subscribe editor.onDidAddSelection(@onSelectionAdded)
@subscribe editor, 'decoration-added', @onDecorationChanged
@subscribe editor, 'decoration-removed', @onDecorationChanged
@subscribe editor, 'decoration-changed', @onDecorationChanged
@@ -721,17 +719,22 @@ EditorComponent = React.createClass
@pendingChanges.push(change)
@requestUpdate() if editor.intersectsVisibleRowRange(change.start, change.end + 1) # TODO: Use closed-open intervals for change events
onSelectionChanged: (selection) ->
onSelectionAdded: (selection) ->
{editor} = @props
@subscribe selection, 'screen-range-changed', => @onSelectionChanged(selection)
@subscribe selection, 'destroyed', =>
@onSelectionChanged(selection)
@unsubscribe(selection)
if editor.selectionIntersectsVisibleRowRange(selection)
@selectionChanged = true
@requestUpdate()
onSelectionAdded: (selection) ->
onSelectionChanged: (selection) ->
{editor} = @props
if editor.selectionIntersectsVisibleRowRange(selection)
@selectionChanged = true
@selectionAdded = true
@requestUpdate()
onScrollTopChanged: ->

View File

@@ -324,6 +324,12 @@ class Editor extends Model
onDidRemoveCursor: (callback) ->
@emitter.on 'did-remove-cursor', callback
onDidAddSelection: (callback) ->
@emitter.on 'did-add-selection', callback
onDidRemoveSelection: (callback) ->
@emitter.on 'did-remove-selection', callback
# Retrieves the current {TextBuffer}.
getBuffer: -> @buffer
@@ -2315,12 +2321,14 @@ class Editor extends Model
return selection
else
@emit 'selection-added', selection
@emitter.emit 'did-add-selection', selection
selection
# Remove the given selection.
removeSelection: (selection) ->
_.remove(@selections, selection)
@emit 'selection-removed', selection
@emitter.emit 'did-remove-selection', selection
# Reduce one or more selections to a single empty selection based on the most
# recently added cursor.