Check that the ace text matches ShareJS each time

This commit is contained in:
James Allen 2014-04-07 11:23:21 +01:00
parent 2288591bae
commit 6ad8566e24
2 changed files with 19 additions and 4 deletions

View file

@ -1,6 +1,7 @@
define [
"editor/ShareJsDoc"
"libs/backbone"
"libs/underscore"
], (ShareJsDoc) ->
class Document
@getDocument: (ide, doc_id) ->
@ -13,14 +14,25 @@ define [
@connected = @ide.socket.socket.connected
@joined = false
@wantToBeJoined = false
@_checkConsistency = _.bind(@_checkConsistency, @)
@_bindToEditorEvents()
@_bindToSocketEvents()
attachToAce: (ace) ->
@doc?.attachToAce(ace)
attachToAce: (@ace) ->
@doc?.attachToAce(@ace)
editorDoc = @ace.getSession().getDocument()
editorDoc.on "change", @_checkConsistency
detachFromAce: () ->
@doc?.detachFromAce()
editorDoc = @ace.getSession().getDocument()
editorDoc.off "change", @_checkConsistency
_checkConsistency: () ->
editorValue = @ace?.getValue()
sharejsValue = @doc?.getSnapshot()
if editorValue != sharejsValue
@_onError "error", new Error("Editor text does not match server text")
getSnapshot: () ->
@doc?.getSnapshot()

View file

@ -174,8 +174,11 @@ define [
meta.client_now = new Date()
meta.recent_events = @recentEvents
errorObj = {}
for key in Object.getOwnPropertyNames(error)
errorObj[key] = error[key]
if typeof error == "object"
for key in Object.getOwnPropertyNames(error)
errorObj[key] = error[key]
else if typeof error == "string"
errorObj.message = error
$.ajax
url: "/error/client"
type: "POST"