{"action":"created","issue":{"url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3396","labels_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3396/labels{/name}","comments_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3396/comments","events_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3396/events","html_url":"https://github.com/codemirror/CodeMirror/pull/3396","id":95838067,"number":3396,"title":"Preserve newline LF/CRLF for each line","user":{"login":"mihailik","id":4041967,"avatar_url":"https://avatars.githubusercontent.com/u/4041967?v=3","gravatar_id":"","url":"https://api.github.com/users/mihailik","html_url":"https://github.com/mihailik","followers_url":"https://api.github.com/users/mihailik/followers","following_url":"https://api.github.com/users/mihailik/following{/other_user}","gists_url":"https://api.github.com/users/mihailik/gists{/gist_id}","starred_url":"https://api.github.com/users/mihailik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mihailik/subscriptions","organizations_url":"https://api.github.com/users/mihailik/orgs","repos_url":"https://api.github.com/users/mihailik/repos","events_url":"https://api.github.com/users/mihailik/events{/privacy}","received_events_url":"https://api.github.com/users/mihailik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-18T16:26:00Z","updated_at":"2015-07-19T01:28:43Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/codemirror/CodeMirror/pulls/3396","html_url":"https://github.com/codemirror/CodeMirror/pull/3396","diff_url":"https://github.com/codemirror/CodeMirror/pull/3396.diff","patch_url":"https://github.com/codemirror/CodeMirror/pull/3396.patch"},"body":"Implements #3395 \r\n\r\nThe idea is to store EOL characters inside of `CodeMirror.Line.text`. And four broad areas needed careful adjustments:\r\n\r\n1. Operations like getValue, getRange and similar will no longer `join(\"\\n\")`, instead they `join(\"\")`. Of course, it's more complicated -- when `lineSep` optional argument is provided, the native EOLs need to be replaced with a given `lineSep`. That logic is in the new function `joinSep(lines, lineSep)`.\r\n\r\n2. Cursor movement left-right need to skip over now-explicitly-present EOLs when moving in either direction. Given that EOLs can be either of `\\n`, `\\r\\n` and `\\r`, a new function `getLineSep(lineText)` is introduced. It's a cheap call, not allocating any objects and simply checking the last two characters. Several places where lineObj.text.length is used have been adjusted to account for the EOL length.\r\n\r\n3. Highlight modes may not be prepared for EOLs, so StringStream is adjusted to skip over those. Again, care has been taken to avoid creating string objects unnecessarily.\r\n\r\n4. Position/index conversion functions previously calculated offsets by aggregating over `line.text.length+1` where `+1` is for the EOL character. The new logic should just aggregate over `line.text.length`.\r\n\r\nI've tested it with `/codemirror/demo/preview.html` -- it works exactly as before (at least in Chrome on desktop). Will try with more use cases."},"comment":{"url":"https://api.github.com/repos/codemirror/CodeMirror/issues/comments/122610727","html_url":"https://github.com/codemirror/CodeMirror/pull/3396#issuecomment-122610727","issue_url":"https://api.github.com/repos/codemirror/CodeMirror/issues/3396","id":122610727,"user":{"login":"mihailik","id":4041967,"avatar_url":"https://avatars.githubusercontent.com/u/4041967?v=3","gravatar_id":"","url":"https://api.github.com/users/mihailik","html_url":"https://github.com/mihailik","followers_url":"https://api.github.com/users/mihailik/followers","following_url":"https://api.github.com/users/mihailik/following{/other_user}","gists_url":"https://api.github.com/users/mihailik/gists{/gist_id}","starred_url":"https://api.github.com/users/mihailik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mihailik/subscriptions","organizations_url":"https://api.github.com/users/mihailik/orgs","repos_url":"https://api.github.com/users/mihailik/repos","events_url":"https://api.github.com/users/mihailik/events{/privacy}","received_events_url":"https://api.github.com/users/mihailik/received_events","type":"User","site_admin":false},"created_at":"2015-07-19T01:28:43Z","updated_at":"2015-07-19T01:28:43Z","body":"I don't see what you're saying at all, I'm sorry. Existing users already using LF convention would have their LFs exactly the same way. The whole point is to *preserve* the EOLs as is, whatever they are.\r\n\r\nLiking your suggestion on 'userland' solution a lot, but sadly neither Bill Gates nor Linus Torvalds seem to be over-excited on the idea. Unless you manage to convince them, let's assume the input files may come with arbitrary convention."}}