mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add Editor::onDidAdd/RemoveSelection
Also update EditorComponent to use the new ::onDidAddSelection method.
This commit is contained in:
@@ -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: ->
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user