mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Check that the ace text matches ShareJS each time
This commit is contained in:
parent
2288591bae
commit
6ad8566e24
2 changed files with 19 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue