diff --git a/src/editor-component.coffee b/src/editor-component.coffee index 847aa9d57..88bea3e83 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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: -> diff --git a/src/editor.coffee b/src/editor.coffee index dfd355679..3a548a713 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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.