From 9cf9a7e4fc76c80a111bab8283ab5678b2de63b8 Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 12 Mar 2018 13:33:54 +0000 Subject: [PATCH 1/2] Fix CM/ShareJS adapter using old CM api Fixes bug where deleting text in CM would throw an error in some circumstances --- .../ide/editor/sharejs/vendor/client/cm.coffee | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee b/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee index d2cf8f2dce..7715beccc1 100644 --- a/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee +++ b/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee @@ -12,21 +12,10 @@ applyCMToShareJS = (editorDoc, delta, doc) -> while i < delta.from.line startPos += editorDoc.lineInfo(i).text.length + 1 # Add 1 for '\n' i++ - startPos += delta.from.ch - if delta.to.line == delta.from.line && - delta.to.ch == delta.from.ch # Then nothing was removed. - doc.insert startPos, delta.text.join '\n' - else - delLen = delta.to.ch - delta.from.ch - while i < delta.to.line - delLen += editorDoc.lineInfo(i).text.length + 1 # Add 1 for '\n' - i++ - doc.del startPos, delLen - doc.insert startPos, delta.text.join '\n' if delta.text - - applyCMToShareJS editorDoc, delta.next, doc if delta.next + doc.del startPos, delta.removed.join('\n').length if delta.removed + doc.insert startPos, delta.text.join('\n') if delta.text # 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 From 8abf3593fb4e3218c2e69bece0365f0a11aa2bfb Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Mon, 12 Mar 2018 13:36:16 +0000 Subject: [PATCH 2/2] Prevent CM/Sharejs adapter from overwriting value in editor --- .../public/coffee/ide/editor/sharejs/vendor/client/cm.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee b/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee index 7715beccc1..b6ea0ede63 100644 --- a/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee +++ b/services/web/public/coffee/ide/editor/sharejs/vendor/client/cm.coffee @@ -36,8 +36,9 @@ window.sharejs.extendDoc 'attach_cm', (editor, keepEditorContents) -> 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.getText() + # Removed editor.setValue here as it would cause recursive loops if + # consistency check failed - because setting the value would trigger + # the change event , 0 if keepEditorContents