From c85e9ba3b1d1effd77625de999b34b1c972129bf Mon Sep 17 00:00:00 2001 From: Alasdair Smith Date: Tue, 20 Feb 2018 13:13:24 +0000 Subject: [PATCH] Instead of setting value of CM, swap Docs This allows for tracking changes on individual docs (i.e. files), instead of just changes to the editor. This is similar to how Ace works with sessions --- .../public/coffee/ide/editor/directives/cmEditor.coffee | 5 +++-- services/web/public/es/rich-text.js | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/cmEditor.coffee b/services/web/public/coffee/ide/editor/directives/cmEditor.coffee index a0e475688b..1241e54415 100644 --- a/services/web/public/coffee/ide/editor/directives/cmEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/cmEditor.coffee @@ -17,8 +17,9 @@ define [ attachToCM(sharejsDoc) attachToCM = (sharejsDoc) -> - cm.setValue(sharejsDoc.getSnapshot()) - sharejsDoc.attachToCM(cm) + setTimeout () -> + Frontend.richText.openDoc(cm, sharejsDoc.getSnapshot()) + sharejsDoc.attachToCM(cm) detachFromCM = (sharejsDoc) -> sharejsDoc.detachFromCM() diff --git a/services/web/public/es/rich-text.js b/services/web/public/es/rich-text.js index b07155829d..14399c1663 100644 --- a/services/web/public/es/rich-text.js +++ b/services/web/public/es/rich-text.js @@ -1,5 +1,11 @@ -import CodeMirror from 'codemirror' +import CodeMirror, { Doc } from 'codemirror' export function init(rootEl) { return CodeMirror(rootEl) } + +export function openDoc(cm, content) { + const newDoc = Doc(content) + cm.swapDoc(newDoc) + return newDoc +}