6

I started this little project where I would do real time collaboration on code using CodeMirror.

I have a msgs system setup such its easy to pass objects from one user to another. My problem is getting it integrated with CodeMirror. I found out that it have events for onchange and a replaceRange(string, from, to).

I pass the onchange objects to the other users and uses the replaceRange to update the view. Problem is then when using replaceRange, it triggers an new onchange and it sends msgs back and forward. Anyone know if there are some way of updating the local view without it triggering an onchange. Or suggestings for other paths to take. (the msgs system is already set up and its easy to pass javascript objects to other clients).

Andrew Lee
  • 10,127
  • 3
  • 46
  • 40
Poul K. Sørensen
  • 16,950
  • 21
  • 126
  • 283

2 Answers2

8

You Can Use Firepad

FirePad is an open-source (on GitHub) realtime collaborative plug-in to codemirror. You can get it setup with codemirror in 4 extra lines of code and a few minutes. It's uses Firebase for the backend.

DrFriedParts
  • 469
  • 10
  • 18
4

To get this to work properly, you'll have to merge changes as well. See http://ot.substance.io/ for a demo of an open-source solution (also using CodeMirror).

Marijn
  • 8,691
  • 2
  • 34
  • 37
  • 1
    silent = true; update codemirror; silent =false; was what i needed to solve it. – Poul K. Sørensen Dec 02 '12 at 13:13
  • @pksorensen Hello, I have exactly the same problem. I read your comment but I am not sure what is silent here ? I could not really find anything of the kind in code mirror manual. Do you mind sharing the solution or may be elaborating it a bit?Please do that favor. Thanks – systemdebt Apr 11 '15 at 10:25
  • Sorry, over 2 years since i looked at this. But reading my comment I assume that there was a api that allowed to supress the change updates. properly something named silent. Sorry that I cant be of more help at this point – Poul K. Sørensen Apr 11 '15 at 23:50
  • @Simrankaur Have you found a solution to this? I'm experiencing the same problem :( – caravana_942 Jul 11 '20 at 15:28