-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Inconsistent positions/ranges for files that contain \r\n
as a line separator.
#35
Comments
Why don't you simply use |
I haven't tested it on windows but i would assume that the problem is the same. Because For user files i would prefer if i didn't have to replace |
If you use Yjs for collaborative editing, then you probably expect that all users (probably on different platforms) end up with the same content. It is not entirely clear to me why one would choose to use I need good arguments to make good decisions. A fix for this codemirror-specific issue is quite complicated to implement and will have impact on other editor bindings. I'm currently working under the assumption that it would be preferable for everyone to use the same line-ending format. If you store files on the filesystem, I suggest that you manually transform the \n to \n\r on windows and that you transfer it back before you intert the content into codemirror. Since I don't understand the issue, it will probably be stalled until I do. |
Codemirror supports three different line separators: The problem i have is that a user can open a file they have created using a different editor that uses A way around that would be to replace all I don't see why fixing this would impact other editor bindings, because it should just slightly adjust the positions reported by codemirror and the positions when yjs changes are dispatched to codemirror. So it should only affect this extension. |
As I said, the issue is quite complicated to fix and will have impact on performance. My point stands, I don't see any use-case for using different line breaks in a collaborative environment. A Linux user would insert I could replace Windows line endings with normal ones before I insert them in the Yjs structure. codemirror would render In any case, I will put this on the back burner as I don't deem this a high-priority issue. Feel free to contact me if you want to sponsor work on this. |
I still don't think the os actually matters and it is also not an issue of mixing different line breaks. But i do understand that if this is difficult to fix, it's probably not worth it, since it can still be worked around. |
Describe the bug
Codemirror treats the line separator
\r\n
as a single character which means ranges and positions are different from yjs.If a file contains
\r\n
then new characters written after it appear correctly in codemirror but are actually added at the wrong position in the yjs document.Also adding text directly to the end of the yjs document throws an error because the change will be out of range for codemirror.
It seems like
\r\n
being only one character is intended behavior for codemirror and positions should be manually adjusted.To Reproduce
Steps to reproduce the behavior:
1\r\n2
where\r\n
is a line separator, not normal text.1\r\n23
in codemirror but1\r\n32
in yjs.Expected behavior
Ranges and positions are always consistent between yjs and codemirror.
Environment Information
The text was updated successfully, but these errors were encountered: