 
   @detach_cm = ->
     # TODO: can we remove the insert and delete event callbacks?
-    editor.off 'onChange', editorListener
+    editorDoc.off 'change', editorListener
     delete @detach_cm
 
   return

    throw new Error 'Only text documents can be attached to CodeMirror2'

  sharedoc = @
  check = ->
    window.setTimeout ->
        editorText = editor.getValue()

  # Listen for edits in CodeMirror.
  editorListener = (ed, change) ->
    return if suppress
    applyCMToShareJS editorDoc, change, sharedoc
    check()

  editorDoc.on 'change', editorListener

  @on 'insert', (pos, text) ->
    suppress = true
