Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update share-codemirror.js #6

Closed
wants to merge 1 commit into from
Closed

Update share-codemirror.js #6

wants to merge 1 commit into from

Conversation

domagojk
Copy link

@domagojk domagojk commented Dec 2, 2014

Using a current implementation of sharejs with codemirror, multiple cursors are not working.
This is because change event is fireing AFTER it has been applied in codemirror document. For this reason, it is not good to rely on cm.lineinfo() since it may contain characters that are not inserted in sharejs ctx.
Calculating position index from ctx.get() does the trick and with it, you can safely use codemirrors multiple cursors.
("indexFromPos" is a function derived from codemirror lib)

Using a current implementation of sharejs with codemirror, multiple cursors are not working. 
This is because change event is fireing AFTER it has been applied in codemirror document. For this reason, it is not good to rely on cm.lineinfo() since it may contain characters that are not inserted in sharejs ctx.
Calculating position index from ctx.get() does the trick and with it, you can safely use codemirrors multiple cursors.
("indexFromPos" is a function derived from codemirror lib)
@aslakhellesoy
Copy link
Contributor

Thanks for this @domagojk

I would really like to see a test for this. Could you write a test that fails without your fixes and passes with it?

@domagojk
Copy link
Author

domagojk commented Dec 2, 2014

I dont know how to write the test, since I think there is no codemirror function (in its API) to insert multiple cursor changes.
Using cm.replaceRange multiple times is not the same... I can only suggest to try it yourself, so you can add a breakpoint before checking ctx.val() and cm.getValue(), set up some multiple cursors, press some key and you will see that even at first change event cm.getValue() is already filled with all changes so check() fails and messes up your document since its replaced with ctx.get()

Maybe there is a way to write phantomJS or casperJS tests for this?

@aslakhellesoy
Copy link
Contributor

How do I set up multiple cursors? I couldn't find anything about it in the codemirror manual.

@domagojk
Copy link
Author

domagojk commented Dec 2, 2014

Hold Ctrl/Cmd and click on lines/ch you want them

@domagojk
Copy link
Author

domagojk commented Dec 2, 2014

I forgot to mention, In this commit I also added "suppress" flag on reverting to ctx.get()
I got some infinite loops when I was debugging and this prevented it, but that could be from my code (which I deleted later) so please remove it if this is unnecessary

@aslakhellesoy
Copy link
Contributor

Thanks! I'm quite busy, but you'll automatically get an update when/if I merge this in. I'm sure it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants