mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #375 from sharelatex/as-clean-up-sharejs
Clean up ShareJS
This commit is contained in:
commit
363ab86b24
2 changed files with 14 additions and 6 deletions
|
@ -106,7 +106,7 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
||||||
# the work of editorDoc.insert and editorDoc.remove manually. These methods are
|
# the work of editorDoc.insert and editorDoc.remove manually. These methods are
|
||||||
# copied from ace.js doc#insert and #remove, and then inject the remote:true
|
# copied from ace.js doc#insert and #remove, and then inject the remote:true
|
||||||
# flag into the delta.
|
# flag into the delta.
|
||||||
doc.on 'insert', (pos, text) ->
|
onInsert = (pos, text) ->
|
||||||
if (editorDoc.getLength() <= 1)
|
if (editorDoc.getLength() <= 1)
|
||||||
editorDoc.$detectNewLine(text)
|
editorDoc.$detectNewLine(text)
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
||||||
suppress = false
|
suppress = false
|
||||||
check()
|
check()
|
||||||
|
|
||||||
doc.on 'delete', (pos, text) ->
|
onDelete = (pos, text) ->
|
||||||
range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
|
range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
|
||||||
start = editorDoc.clippedPos(range.start.row, range.start.column)
|
start = editorDoc.clippedPos(range.start.row, range.start.column)
|
||||||
end = editorDoc.clippedPos(range.end.row, range.end.column)
|
end = editorDoc.clippedPos(range.end.row, range.end.column)
|
||||||
|
@ -144,8 +144,12 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
||||||
suppress = false
|
suppress = false
|
||||||
check()
|
check()
|
||||||
|
|
||||||
|
doc.on 'insert', onInsert
|
||||||
|
doc.on 'delete', onDelete
|
||||||
|
|
||||||
doc.detach_ace = ->
|
doc.detach_ace = ->
|
||||||
# TODO: can we remove the insert and delete event callbacks?
|
doc.removeListener 'insert', onInsert
|
||||||
|
doc.removeListener 'delete', onDelete
|
||||||
editorDoc.removeListener 'change', editorListener
|
editorDoc.removeListener 'change', editorListener
|
||||||
delete doc.detach_ace
|
delete doc.detach_ace
|
||||||
|
|
||||||
|
|
|
@ -61,14 +61,14 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
||||||
|
|
||||||
editorDoc.on 'change', editorListener
|
editorDoc.on 'change', editorListener
|
||||||
|
|
||||||
@on 'insert', (pos, text) ->
|
onInsert = (pos, text) ->
|
||||||
suppress = true
|
suppress = true
|
||||||
# All the primitives we need are already in CM's API.
|
# All the primitives we need are already in CM's API.
|
||||||
editor.replaceRange text, editor.posFromIndex(pos)
|
editor.replaceRange text, editor.posFromIndex(pos)
|
||||||
suppress = false
|
suppress = false
|
||||||
check()
|
check()
|
||||||
|
|
||||||
@on 'delete', (pos, text) ->
|
onDelete = (pos, text) ->
|
||||||
suppress = true
|
suppress = true
|
||||||
from = editor.posFromIndex pos
|
from = editor.posFromIndex pos
|
||||||
to = editor.posFromIndex (pos + text.length)
|
to = editor.posFromIndex (pos + text.length)
|
||||||
|
@ -76,8 +76,12 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
||||||
suppress = false
|
suppress = false
|
||||||
check()
|
check()
|
||||||
|
|
||||||
|
@on 'insert', onInsert
|
||||||
|
@on 'delete', onDelete
|
||||||
|
|
||||||
@detach_cm = ->
|
@detach_cm = ->
|
||||||
# TODO: can we remove the insert and delete event callbacks?
|
@removeListener 'insert', onInsert
|
||||||
|
@removeListener 'delete', onDelete
|
||||||
editorDoc.off 'change', editorListener
|
editorDoc.off 'change', editorListener
|
||||||
delete @detach_cm
|
delete @detach_cm
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue