Cursor Transform Issue with CodeMirror

20 views
Skip to first unread message

Curran Kelleher

unread,
Jan 31, 2018, 5:54:25 AM1/31/18
to ShareJS
Greetings,

I'm struggling with getting cursor transformation right with CodeMirror. If anyone would be willing to help, it would be greatly appreciated.

The project is codemirror-binding, and the issue I'm facing is as follows:
  • The cursor is being transformed (moved to the left or right) unnecessarily when the remote edit occurs on a line before the line where the cursor is.
  • The left-right transform should only occur if the cursor is on the same line as the remote edit.
Interestingly, this issue is not present in text-diff-binding, which uses the same implementation logic for cursor transforms (at least as far as I can tell), just using different APIs (DOM Textarea API vs. CodeMirror API). For comparison, my gut feeling is that the following bit of code is where the issue is, but I'm not sure how to fix it:

To reproduce the behavior:

  • run the test project
  • enter lots of text on multiple lines
  • place your cursor on any line other than the first one (where 'd' is repeatedly being inserted each second)
  • observe that your cursor is transformed to the right in the CodeMirror instance (on the bottom)
  • observe that your cursor is not transformed to the right in the textarea instance (on the top)

Any ideas or help would be greatly appreciated! Thank you.


Best regards,

Curran

John Hewson

unread,
Jan 31, 2018, 1:12:50 PM1/31/18
to sha...@googlegroups.com
Hi Curran,

I took a super quick look at this and I wonder if the issue is related to the fact that the new content is not added to code mirror until this.update() is called and you’re calling posFromIndex before then on what at that point is the old content.

Moving the two lines which call posFromIndex below this.update() might fix it?

John


--
You received this message because you are subscribed to the Google Groups "ShareJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharejs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Curran Kelleher

unread,
Feb 1, 2018, 4:12:47 AM2/1/18
to ShareJS
Hi John,

Thank you so much for this suggestion. It worked!

Released a new codemirror-binding version with the fix (and a fix for a scrolling issue).

Best regards,
Curran
Reply all
Reply to author
Forward
0 new messages