Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Add Cursor::onDidChangePosition and ::onDidDestroy and deprecate ::on
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Sobo committed Sep 4, 2014
1 parent fed879e commit 3aabe90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/cursor.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{Point, Range} = require 'text-buffer'
{Model} = require 'theorist'
{Emitter} = require 'event-kit'
_ = require 'underscore-plus'
Grim = require 'grim'

# Extended: The `Cursor` class represents the little blinking line identifying
# where text can be inserted.
Expand Down Expand Up @@ -42,6 +44,8 @@ class Cursor extends Model

# Instantiated by an {Editor}
constructor: ({@editor, @marker, id}) ->
@emitter = new Emitter

@assignId(id)
@updateVisibility()
@marker.onDidChange (e) =>
Expand All @@ -65,13 +69,31 @@ class Cursor extends Model
textChanged: textChanged

@emit 'moved', movedEvent
@emitter.emit 'did-change-position'
@editor.cursorMoved(this, movedEvent)
@marker.onDidDestroy =>
@destroyed = true
@editor.removeCursor(this)
@emit 'destroyed'
@emitter.emit 'did-destroy'
@emitter.dispose()
@needsAutoscroll = true

onDidChangePosition: (callback) ->
@emitter.on 'did-change-position', callback

onDidDestroy: (callback) ->
@emitter.on 'did-destroy', callback

on: (eventName) ->
switch eventName
when 'moved'
Grim.deprecate("Use Cursor::onDidChangePosition instead")
when 'destroyed'
Grim.deprecate("Use Cursor::onDidDestroy instead")

super

destroy: ->
@marker.destroy()

Expand Down
3 changes: 1 addition & 2 deletions src/editor-component.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,7 @@ EditorComponent = React.createClass
onStoppedScrollingAfterDelay: null # created lazily

onCursorAdded: (cursor) ->
@subscribe cursor, 'moved', @onCursorMoved
@subscribe cursor, 'destroyed', => @unsubscribe(cursor)
@subscribe cursor.onDidChangePosition @onCursorMoved

onCursorMoved: ->
@cursorMoved = true
Expand Down

0 comments on commit 3aabe90

Please sign in to comment.