diff --git a/src/editor-component.coffee b/src/editor-component.coffee index f2d4cbc65..d70cf9a14 100644 --- a/src/editor-component.coffee +++ b/src/editor-component.coffee @@ -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) diff --git a/src/editor.coffee b/src/editor.coffee index b661d3ffe..bf40518bf 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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}