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

Applying \r\n as two seperate edits causes the editor to render 2 new lines instead of 1 #1427

Closed
Place1 opened this issue Apr 25, 2019 · 1 comment

Comments

@Place1
Copy link

Place1 commented Apr 25, 2019

Hey, I think i've run into a bug with how monaco handles CR LF characters. If you use the below script in the monaco playground you can see that applying \r\n as two separate edits causes the editor to display 2 lines rather than 1. If you apply \r\n in a single edit then this isn't a problem.

monaco-editor version: playground
Browser: firefox
OS: windows 10

Steps or JS usage snippet reproducing the issue:

var editor = monaco.editor.create(document.getElementById("container"), {
	value: "hello",
	language: "javascript"
});

editor.getModel().applyEdits([
    {
        text: '\r',
        range: new monaco.Range(1, 1, 1, 1),
    },
]);

editor.getModel().applyEdits([
    {
        text: '\n',
        range: new monaco.Range(1, 2, 1, 2),
    },
]);

console.log(JSON.stringify(editor.getModel().getValue()))
@alexdima
Copy link
Member

This is as designed. By design, we do not allow a file to be in a mixed line ending situation. Therefore, if the model is configured to have \r\n\ as EOL sequence, when you insert \r, it will be "fixed" to \r\n. Also, when you insert \n, it will be "fixed" to \n.

There are some people who would still want mixed line endings in their files 🤷‍♂ ... Let's track that at microsoft/vscode#127

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants