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

Public API for controlling the EOL style #2019

Closed
mrozekma opened this issue Jun 25, 2020 · 2 comments
Closed

Public API for controlling the EOL style #2019

mrozekma opened this issue Jun 25, 2020 · 2 comments
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@mrozekma
Copy link

For cross-platform reasons (see FirebaseExtended/firepad#315), I need to force the editor to use a particular line ending. I see setEOL/pushEOL on the model, but that seems to change the current contents of the editor but not set the EOL permanently -- if the editor is cleared or replaced with other text, the set EOL can be lost.

From poking around the code, I found that the default EOL comes from SimpleResourcePropertiesService.getEOL, and varies by platform, but first it tries to read the files.eol configuration value. Thus I can fix the problem by setting that value:

import { StaticServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices';
StaticServices.configurationService.get().updateValue('files.eol', '\r\n');

This works, but I don't think this is supposed to be a public interface. Can some better way to enforce a particular line ending be added to the editor or text model?

@brijeshb42
Copy link
Contributor

What we used as a solution was to replace all setValue calls with -

function newSetValue(model, newValue) {
  model.applyEdits([{ text: newValue, range: model.getFullModelRange()}]);
}

@alexdima
Copy link
Member

alexdima commented Sep 8, 2020

Yes, setValue calls will reset the EOL to the new content passed in. The solution is to change the EOL after calling setValue or to use applyEdits to change the contents.

@alexdima alexdima closed this as completed Sep 8, 2020
@alexdima alexdima added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Sep 8, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Oct 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants