Operational-Transformation / ot.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set a new doc and revision

benbro opened this issue · comments

Is it possible to reset the ot.EditorClient instance?
I'm trying to load a new doc to an existing EditorClient using a CodeMirror adapter.

I tried something like:

cmAdapter.silent = true;
cm.setValue(str);
cmClient.revision = revision;
cmClient.state = new ot.Client.Synchronized();
//no way to reset the undo manager? cmClient.undoManager
cmClient.cursor = new Cursor(0, 0);
cmAdapter.silent = false;

I'm getting an error:
Error: There is no pending operation.
Not sure how to fix it.

Is it possible to add a setDoc function in ot.Client and ot.EditorClient?

Thanks

Why are you trying to reset an EditorClient? Why not simply create a new one?

You mean setting the adapter, client and CodeMirror instance to null and removing the old CodeMirror element from the DOM?

var cmAdapter_ = null;
var cmClient_ = null;
var cm_ = null;
cmParentEl.removeChild(cmEl);

I thought that using the same setup and just resting everything with a new doc and revision is cleaner.
This way you can use the same Socket.IO connection and just reset the OT state when getting a doc message.

Anyway, if it's not a direction you want to take please close this issue and I'll use your suggestion and create a new one.

Thank you.

I don't think that it is necessary to create a new CodeMirror element, but I would definitely create new instances of CodeMirrorAdapter and EditorClient. In my opinion, it is cleaner to create new objects and explicitly copy some state from old objects than to reset the whole state except some parts of it (possibly forgetting to reset some attributes).

Using the same CodeMirror instance with new instances of CodeMirrorAdapter and EditorClient will be good.
Can you expose a method to the 'change', 'cursorActivity' and 'blur' listeners on the CodeMirror instances so we won't be left with zombie listeners?

If you think it's a good idea I can create PR with a dispose function that does that on CodeMirrorAdapter.

This PR let us remove the CodeMirror event listeners
#13

Implemented as CodeMirrorAdapter.prototype.detach in f172b4f. Let me know if you have any other issues. If not, I will publish a minor release later this week.

Hey, I just wanted to let you know that I've just released version 0.0.11 which contains fixes for the bugs you spotted. Thanks again for reporting them!

Thank you. Works great.