mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-28 23:02:23 +00:00
Allow Documents to be attached to CM
This commit is contained in:
parent
09fbafa1f6
commit
7783e18a50
2 changed files with 33 additions and 18 deletions
|
@ -26,7 +26,8 @@ define [
|
|||
@connected = @ide.socket.socket.connected
|
||||
@joined = false
|
||||
@wantToBeJoined = false
|
||||
@_checkConsistency = _.bind(@_checkConsistency, @)
|
||||
@_checkAceConsistency = _.bind(@_checkConsistency, @, @ace)
|
||||
@_checkCMConsistency = _.bind(@_checkConsistency, @, @cm)
|
||||
@inconsistentCount = 0
|
||||
@_bindToEditorEvents()
|
||||
@_bindToSocketEvents()
|
||||
|
@ -34,32 +35,43 @@ define [
|
|||
attachToAce: (@ace) ->
|
||||
@doc?.attachToAce(@ace)
|
||||
editorDoc = @ace.getSession().getDocument()
|
||||
editorDoc.on "change", @_checkConsistency
|
||||
editorDoc.on "change", @_checkAceConsistency
|
||||
@ide.$scope.$emit 'document:opened', @doc
|
||||
|
||||
detachFromAce: () ->
|
||||
@doc?.detachFromAce()
|
||||
editorDoc = @ace?.getSession().getDocument()
|
||||
editorDoc?.off "change", @_checkConsistency
|
||||
editorDoc?.off "change", @_checkAceConsistency
|
||||
@ide.$scope.$emit 'document:closed', @doc
|
||||
|
||||
|
||||
attachToCM: (@cm) ->
|
||||
@doc?.attachToCM(@cm)
|
||||
@cm?.on "change", @_checkCMConsistency
|
||||
@ide.$scope.$emit 'document:opened', @doc
|
||||
|
||||
detachFromCM: () ->
|
||||
@doc?.detachFromCM()
|
||||
@cm?.off "change", @_checkCMConsistency
|
||||
@ide.$scope.$emit 'document:closed', @doc
|
||||
|
||||
submitOp: (args...) -> @doc?.submitOp(args...)
|
||||
|
||||
_checkConsistency: () ->
|
||||
# We've been seeing a lot of errors when I think there shouldn't be
|
||||
# any, which may be related to this check happening before the change is
|
||||
# applied. If we use a timeout, hopefully we can reduce this.
|
||||
setTimeout () =>
|
||||
editorValue = @ace?.getValue()
|
||||
sharejsValue = @doc?.getSnapshot()
|
||||
if editorValue != sharejsValue
|
||||
@inconsistentCount++
|
||||
else
|
||||
@inconsistentCount = 0
|
||||
_checkConsistency: (editor) ->
|
||||
return () =>
|
||||
# We've been seeing a lot of errors when I think there shouldn't be
|
||||
# any, which may be related to this check happening before the change is
|
||||
# applied. If we use a timeout, hopefully we can reduce this.
|
||||
setTimeout () =>
|
||||
editorValue = editor?.getValue()
|
||||
sharejsValue = @doc?.getSnapshot()
|
||||
if editorValue != sharejsValue
|
||||
@inconsistentCount++
|
||||
else
|
||||
@inconsistentCount = 0
|
||||
|
||||
if @inconsistentCount >= 3
|
||||
@_onError new Error("Editor text does not match server text")
|
||||
, 0
|
||||
if @inconsistentCount >= 3
|
||||
@_onError new Error("Editor text does not match server text")
|
||||
, 0
|
||||
|
||||
getSnapshot: () ->
|
||||
@doc?.getSnapshot()
|
||||
|
|
|
@ -120,6 +120,9 @@ define [
|
|||
attachToAce: (ace) -> @_doc.attach_ace(ace, false, window.maxDocLength)
|
||||
detachFromAce: () -> @_doc.detach_ace?()
|
||||
|
||||
attachToCM: (cm) -> @_doc.attach_cm(cm, false)
|
||||
detachFromCM: () -> @_doc.detach_cm?()
|
||||
|
||||
INFLIGHT_OP_TIMEOUT: 5000 # Retry sending ops after 5 seconds without an ack
|
||||
WAIT_FOR_CONNECTION_TIMEOUT: 500 # If we're waiting for the project to join, try again in 0.5 seconds
|
||||
_startInflightOpTimeout: (update) ->
|
||||
|
|
Loading…
Reference in a new issue