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

Cross-platform collaboration breaks on monaco due to CRLF #41

Closed
Blakeinstein opened this issue Aug 19, 2021 · 7 comments
Closed

Cross-platform collaboration breaks on monaco due to CRLF #41

Blakeinstein opened this issue Aug 19, 2021 · 7 comments

Comments

@Blakeinstein
Copy link

Version info

Firebase: 8.9.1

Firepad: 0.2.0

Monaco: 0.20.0

Test case

Duplicate of FirebaseExtended#315

Steps to reproduce

  1. Open session on macos
  2. Open session on windows
  3. See windows go out of sync

Expected behavior

Consistent behaviour

Actual behavior

Cannot send changes from windows

@0xTheProDev
Copy link

@Blakeinstein Thanks for logging this issue and this has been a long overdue. We should be able to have a consistent way to handle different line endings natively from Firepad itself. But for the time being, you could do something like this in your monaco instance in your app:

+ editor.getModel().setEOL(monaco.editor.EndOfLineSequence.LF);
- editor.setValue(stringContent);
+ editor.getModel().applyEdits([
     {
        range: editor.getModel().getFullRange(),
        text: lineContent.join("\n"),
     }
   ])

and get it resolved. We do the same at Hackerrank.

@Blakeinstein
Copy link
Author

I should also do this when I update options and or language?

@0xTheProDev
Copy link

Only if you update Monaco Model along with them.

@Blakeinstein
Copy link
Author

Blakeinstein commented Aug 19, 2021

+ editor.getModel().setEOL(monaco.editor.EndOfLineSequence.LF);
- editor.setValue(stringContent);
+ editor.getModel().applyEdits([
     {
        range: editor.getModel().getFullRange(),
        text: lineContent.join("\n"),
     }
   ])

I assume all I need are the lines marked with +? What is line content? editor.getModel().getLinesContent()?

@0xTheProDev
Copy link

+ editor.getModel().setEOL(monaco.editor.EndOfLineSequence.LF);
- editor.setValue(stringContent);
+ editor.getModel().applyEdits([
     {
        range: editor.getModel().getFullRange(),
        text: lineContent.join("\n"),
     }
   ])

I assume all I need are the lines marked with +? What is line content? editor.getModel().getLinesContent()?

I am assuming you know changes that you want to update as string[] in lineContent. You can use this API as well. stringContent is the whole content in string.
- marked statements must be removed.

@Blakeinstein
Copy link
Author

Ended up doing the following, and so far it looks like it works.

editor.getModel().setEOL(monaco.editor.EndOfLineSequence.LF)
editor.getModel().applyEdits([
  {
    range: editor.getModel().getFullModelRange(),
    text: editor.getModel().getLinesContent().join('\n')
  }
])

You can close the issue, or keep it open as I see that you guys plan to provide a native solution for this. Thanks!

@0xTheProDev
Copy link

Closing this for now. Let me know if any new problem comes up in this.

@interviewstreet interviewstreet locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants