mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Include ShareJS CM adapter in compiled lib and fix bug with CM adapter
Because the CM & Ace scripts are naively concat-ed together, the Ace applyToShareJS function would be overwritten by the CM version. Also fixes bugs where adapter was calling old version of ShareJS api and the old CM api
This commit is contained in:
parent
f5b6d3ff3e
commit
09fbafa1f6
4 changed files with 12 additions and 10 deletions
|
@ -108,6 +108,7 @@ module.exports = (grunt) ->
|
|||
"public/coffee/ide/editor/sharejs/vendor/client/microevent.coffee"
|
||||
"public/coffee/ide/editor/sharejs/vendor/client/doc.coffee"
|
||||
"public/coffee/ide/editor/sharejs/vendor/client/ace.coffee"
|
||||
"public/coffee/ide/editor/sharejs/vendor/client/cm.coffee"
|
||||
]
|
||||
|
||||
client:
|
||||
|
|
|
@ -21,7 +21,8 @@ SHAREJS_COFFEE_FILES := \
|
|||
public/coffee/ide/editor/sharejs/vendor/types/text-api.coffee \
|
||||
public/coffee/ide/editor/sharejs/vendor/client/microevent.coffee \
|
||||
public/coffee/ide/editor/sharejs/vendor/client/doc.coffee \
|
||||
public/coffee/ide/editor/sharejs/vendor/client/ace.coffee
|
||||
public/coffee/ide/editor/sharejs/vendor/client/ace.coffee \
|
||||
public/coffee/ide/editor/sharejs/vendor/client/cm.coffee
|
||||
LESS_FILES := $(shell find public/stylesheets -name '*.less')
|
||||
CSS_FILES := public/stylesheets/style.css public/stylesheets/ol-style.css
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Range = ace.require("ace/range").Range
|
||||
|
||||
# Convert an ace delta into an op understood by share.js
|
||||
applyToShareJS = (editorDoc, delta, doc, fromUndo) ->
|
||||
applyAceToShareJS = (editorDoc, delta, doc, fromUndo) ->
|
||||
# Get the start position of the range, in no. of characters
|
||||
getStartOffsetPosition = (start) ->
|
||||
# This is quite inefficient - getLines makes a copy of the entire
|
||||
|
@ -81,7 +81,7 @@ window.sharejs.extendDoc 'attach_ace', (editor, keepEditorContents, maxDocLength
|
|||
|
||||
fromUndo = !!(editor.getSession().$fromUndo or editor.getSession().$fromReject)
|
||||
|
||||
applyToShareJS editorDoc, change, doc, fromUndo
|
||||
applyAceToShareJS editorDoc, change, doc, fromUndo
|
||||
|
||||
check()
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# It is heavily inspired from the Ace editor hook.
|
||||
|
||||
# Convert a CodeMirror delta into an op understood by share.js
|
||||
applyToShareJS = (editorDoc, delta, doc) ->
|
||||
applyCMToShareJS = (editorDoc, delta, doc) ->
|
||||
# CodeMirror deltas give a text replacement.
|
||||
# I tuned this operation a little bit, for speed.
|
||||
startPos = 0 # Get character position from # of chars in each line.
|
||||
|
@ -26,7 +26,7 @@ applyToShareJS = (editorDoc, delta, doc) ->
|
|||
doc.del startPos, delLen
|
||||
doc.insert startPos, delta.text.join '\n' if delta.text
|
||||
|
||||
applyToShareJS editorDoc, delta.next, doc if delta.next
|
||||
applyCMToShareJS editorDoc, delta.next, doc if delta.next
|
||||
|
||||
# Attach a CodeMirror editor to the document. The editor's contents are replaced
|
||||
# with the document's contents unless keepEditorContents is true. (In which case
|
||||
|
@ -39,14 +39,14 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|||
check = ->
|
||||
window.setTimeout ->
|
||||
editorText = editor.getValue()
|
||||
otText = sharedoc.getValue()
|
||||
otText = sharedoc.getText()
|
||||
|
||||
if editorText != otText
|
||||
console.error "Text does not match!"
|
||||
console.error "editor: #{editorText}"
|
||||
console.error "ot: #{otText}"
|
||||
# Replace the editor text with the doc snapshot.
|
||||
editor.setValue sharedoc.getValue()
|
||||
editor.setValue sharedoc.getText()
|
||||
, 0
|
||||
|
||||
if keepEditorContents
|
||||
|
@ -64,11 +64,11 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|||
# Listen for edits in CodeMirror.
|
||||
editorListener = (ed, change) ->
|
||||
return if suppress
|
||||
applyToShareJS editor, change, sharedoc
|
||||
applyCMToShareJS editor, change, sharedoc
|
||||
|
||||
check()
|
||||
|
||||
editor.setOption 'onChange', editorListener
|
||||
editor.on 'change', editorListener
|
||||
|
||||
@on 'insert', (pos, text) ->
|
||||
suppress = true
|
||||
|
@ -87,7 +87,7 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) ->
|
|||
|
||||
@detach_cm = ->
|
||||
# TODO: can we remove the insert and delete event callbacks?
|
||||
editor.setOption 'onChange', null
|
||||
editor.off 'onChange', editorListener
|
||||
delete @detach_cm
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue