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
|
||||
# copied from ace.js doc#insert and #remove, and then inject the remote:true
|
||||
# flag into the delta.
|
||||
doc.on 'insert', (pos, text) ->
|
||||
onInsert = (pos, text) ->
|
||||
if (editorDoc.getLength() <= 1)
|
||||
editorDoc.$detectNewLine(text)
|
||||
|
||||
|
@ -129,7 +129,7 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
|||
suppress = false
|
||||
check()
|
||||
|
||||
doc.on 'delete', (pos, text) ->
|
||||
onDelete = (pos, text) ->
|
||||
range = Range.fromPoints offsetToPos(pos), offsetToPos(pos + text.length)
|
||||
start = editorDoc.clippedPos(range.start.row, range.start.column)
|
||||
end = editorDoc.clippedPos(range.end.row, range.end.column)
|
||||
|
@ -144,8 +144,12 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
|||
suppress = false
|
||||
check()
|
||||
|
||||
doc.on 'insert', onInsert
|
||||
doc.on 'delete', onDelete
|
||||
|
||||
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
|
||||
delete doc.detach_ace
|
||||
|
||||
|
|
|
@ -61,14 +61,14 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|||
|
||||
editorDoc.on 'change', editorListener
|
||||
|
||||
@on 'insert', (pos, text) ->
|
||||
onInsert = (pos, text) ->
|
||||
suppress = true
|
||||
# All the primitives we need are already in CM's API.
|
||||
editor.replaceRange text, editor.posFromIndex(pos)
|
||||
suppress = false
|
||||
check()
|
||||
|
||||
@on 'delete', (pos, text) ->
|
||||
onDelete = (pos, text) ->
|
||||
suppress = true
|
||||
from = editor.posFromIndex pos
|
||||
to = editor.posFromIndex (pos + text.length)
|
||||
|
@ -76,8 +76,12 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|||
suppress = false
|
||||
check()
|
||||
|
||||
@on 'insert', onInsert
|
||||
@on 'delete', onDelete
|
||||
|
||||
@detach_cm = ->
|
||||
# TODO: can we remove the insert and delete event callbacks?
|
||||
@removeListener 'insert', onInsert
|
||||
@removeListener 'delete', onDelete
|
||||
editorDoc.off 'change', editorListener
|
||||
delete @detach_cm
|
||||
|
||||
|
|
Loading…
Reference in a new issue