diff options
author | Nathan Vegdahl | 2021-07-02 06:36:09 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-02 06:36:09 +0000 |
commit | 22dca3b111513f4dc0852acf0bfb0229a8661904 (patch) | |
tree | 214add658560426d12d94ccb71929050fb720487 /helix-view/src | |
parent | 230248bbc3e453bab339cb865990c3fa2f518311 (diff) |
Allow last line in file to lack a line break character.
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 0f1f3a8f..9b609429 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -448,15 +448,7 @@ impl Document { } let mut file = std::fs::File::open(&path).context(format!("unable to open {:?}", path))?; - let (mut rope, encoding) = from_reader(&mut file, encoding)?; - - // search for line endings - let line_ending = auto_detect_line_ending(&rope).unwrap_or(DEFAULT_LINE_ENDING); - - // add missing newline at the end of file - if rope.len_bytes() == 0 || !char_is_line_ending(rope.char(rope.len_chars() - 1)) { - rope.insert(rope.len_chars(), line_ending.as_str()); - } + let (rope, encoding) = from_reader(&mut file, encoding)?; let mut doc = Self::from(rope, Some(encoding)); @@ -466,9 +458,9 @@ impl Document { doc.detect_language(theme, loader); } - // Detect indentation style and set line ending. + // Detect indentation style and line ending. doc.detect_indent_style(); - doc.line_ending = line_ending; + doc.line_ending = auto_detect_line_ending(&doc.text).unwrap_or(DEFAULT_LINE_ENDING); Ok(doc) } |