Add and use Editor::observeSelections() and ::observeCursors()

This commit is contained in:
Ben Ogle
2014-09-09 12:08:43 -07:00
parent 3e5666f183
commit 0f83fe54f9
2 changed files with 20 additions and 2 deletions

View File

@@ -345,8 +345,8 @@ EditorComponent = React.createClass
observeEditor: ->
{editor} = @props
@subscribe editor.onDidChangeScreenLines(@onScreenLinesChanged)
@subscribe editor.onDidAddCursor(@onCursorAdded)
@subscribe editor.onDidAddSelection(@onSelectionAdded)
@subscribe editor.observeCursors(@onCursorAdded)
@subscribe editor.observeSelections(@onSelectionAdded)
@subscribe editor.observeDecorations(@onDecorationAdded)
@subscribe editor.onDidRemoveDecoration(@onDecorationRemoved)
@subscribe editor.onDidChangeCharacterWidths(@onCharacterWidthsChanged)

View File

@@ -239,6 +239,15 @@ class Editor extends Model
onDidInsertText: (callback) ->
@emitter.on 'did-insert-text', callback
# Extended: Calls your `callback` when a {Cursor} is added to the editor.
# Immediately calls your callback for each existing cursor.
#
# * `callback` {Function}
# * `selection` {Selection} that was added
observeCursors: (callback) ->
callback(cursor) for cursor in @getCursors()
@onDidAddCursor(callback)
# Extended: Calls your `callback` when a {Cursor} is added to the editor.
#
# * `callback` {Function}
@@ -266,6 +275,15 @@ class Editor extends Model
onDidChangeCursorPosition: (callback) ->
@emitter.on 'did-change-cursor-position', callback
# Extended: Calls your `callback` when a {Selection} is added to the editor.
# Immediately calls your callback for each existing selection.
#
# * `callback` {Function}
# * `selection` {Selection} that was added
observeSelections: (callback) ->
callback(selection) for selection in @getSelections()
@onDidAddSelection(callback)
# Extended: Calls your `callback` when a {Selection} is added to the editor.
#
# * `callback` {Function}