mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-31 21:21:03 -04:00
40 lines
990 B
CoffeeScript
40 lines
990 B
CoffeeScript
define [
|
|
"documentUpdater"
|
|
"ace/range"
|
|
], () ->
|
|
Range = require("ace/range").Range
|
|
Modal = require("utils/Modal")
|
|
|
|
class AceUpdateManager
|
|
constructor: (@editor) ->
|
|
@ide = @editor.ide
|
|
|
|
guidGenerator=()->
|
|
S4 = ()->
|
|
return (((1+Math.random())*0x10000)|0).toString(16).substring(1)
|
|
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4())
|
|
@window_id = guidGenerator()
|
|
|
|
@bindToServerEvents()
|
|
|
|
bindToServerEvents: () ->
|
|
|
|
|
|
|
|
|
|
@ide.socket.on 'reciveTextUpdate', (updating_id, change) =>
|
|
@ide.savingAreaManager.saved()
|
|
if(@window_id == updating_id)
|
|
return
|
|
@ownChange = true
|
|
doc = @editor.getDocument()
|
|
documentUpdater.applyChange doc, change, Range, ()=>
|
|
@ownChange = false
|
|
|
|
bindToDocument: (doc_id, docLines, version) ->
|
|
@current_doc_id = doc_id
|
|
aceDoc = @editor.getDocument()
|
|
aceDoc.on 'change', (change) =>
|
|
if(!@ownChange)
|
|
@ide.socket.emit 'sendUpdate',
|
|
@current_doc_id, @window_id, change.data
|