question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preserve newline LF/CRLF for each line

See original GitHub issue

Currently CodeMirror has a single newline character for the whole document.

That means getValue may return different text to what setValue was called with, depending on the newlines used.

Can the code preserve the ending newline for each line of the document, and use exactly that when concatenating line text for ranges, copy/paste, getValue/setValue please?

Ideally pressing ‘Enter’ would be made smarter too, so it insert the right kind of newline based on the one at the end of the current line.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
mihailikcommented, Jul 20, 2015

Is it really how it should work? This approach produces visual garbage like red dots, may still break addins, and it even glues lines together (try "foo\nbar\rbaz").

Whereas keeping precise account of actual line terminators handles any of those cases and more. Say, you’d be able to implement stricter Unicode conformance, as there are actually more than 3 line terminators in the standard.

Also those compilers that pay attention to EOLs commonly have unit tests for handling the relevant combinations. It would be nice for CodeMirror to be able to open such unit test input files without going weird 😃

1reaction
marijnhcommented, Jul 20, 2015

If you have "foo\nbar\r\nbaz" as your document and your line-ending-determination algorithm decides that it is using "\n" as its main line separator. You create an instance with {doc: "foo\nbar\r\nbaz", lineSeparator: "\n"}, and you’ll get three visible lines foo, bar\r, and baz. I.e. the leftover characters that don’t match the document’s line separator are considered part of the line’s content, and show up in the editor.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Preserve newline LF/CRLF for each line · Issue #3395 - GitHub
Currently CodeMirror has a single newline character for the whole document. That means getValue may return different text to what setValue ...
Read more >
How do I force Git to use LF instead of CR+LF under Windows?
I want to convert all files to have LF line breaks and keep the LF in the files. Remark: I used autocrlf =...
Read more >
Preserve line ending (LF vs. CR/LF) when editing - WinSCP
I have a file in UNIX that originated in Windows, so we expect each line to end with CRLF. However, we have found...
Read more >
CRLF vs. LF: Normalizing Line Endings in Git
Line endings can differ from one OS to another. Learn the history behind CRLF and LF line endings and how to enforce line...
Read more >
Carriage Returns and Line Feeds will ultimately bite you
Carriage Return Line Feed WHAT DOES IT ALL MEAN!?! ... Operating systems in the late 70s all used CR LF together ... Here's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found