|
@@ -36,6 +36,8 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|
|
throw new Error 'Only text documents can be attached to CodeMirror2'
|
|
throw new Error 'Only text documents can be attached to CodeMirror2'
|
|
|
|
|
|
|
|
sharedoc = @
|
|
sharedoc = @
|
|
|
|
|
+ editorDoc = editor.getDoc()
|
|
|
|
|
+
|
|
|
check = ->
|
|
check = ->
|
|
|
window.setTimeout ->
|
|
window.setTimeout ->
|
|
|
editorText = editor.getValue()
|
|
editorText = editor.getValue()
|
|
@@ -64,11 +66,10 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|
|
# Listen for edits in CodeMirror.
|
|
# Listen for edits in CodeMirror.
|
|
|
editorListener = (ed, change) ->
|
|
editorListener = (ed, change) ->
|
|
|
return if suppress
|
|
return if suppress
|
|
|
- applyCMToShareJS editor, change, sharedoc
|
|
|
|
|
-
|
|
|
|
|
|
|
+ applyCMToShareJS editorDoc, change, sharedoc
|
|
|
check()
|
|
check()
|
|
|
|
|
|
|
|
- editor.on 'change', editorListener
|
|
|
|
|
|
|
+ editorDoc.on 'change', editorListener
|
|
|
|
|
|
|
|
@on 'insert', (pos, text) ->
|
|
@on 'insert', (pos, text) ->
|
|
|
suppress = true
|
|
suppress = true
|
|
@@ -87,7 +88,7 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|
|
|
|
|
|
|
@detach_cm = ->
|
|
@detach_cm = ->
|
|
|
# TODO: can we remove the insert and delete event callbacks?
|
|
# TODO: can we remove the insert and delete event callbacks?
|
|
|
- editor.off 'onChange', editorListener
|
|
|
|
|
|
|
+ editorDoc.off 'change', editorListener
|
|
|
delete @detach_cm
|
|
delete @detach_cm
|
|
|
|
|
|
|
|
return
|
|
return
|