diff options
author | Ivan Tham | 2021-06-07 11:33:55 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-08 02:38:56 +0000 |
commit | 82fdfdc38e8309a36330455e65cc34b7395ac299 (patch) | |
tree | e622b84920e6815e730c8352f3270db97817dbf7 /helix-view | |
parent | ea6667070f05227f5d87eaf977ca0c7ddc982c0a (diff) |
Add missing newline to end of file on load
Fix #152
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 783e1117..c9ea4d7a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -147,7 +147,12 @@ impl Document { Rope::from("\n") } else { let file = File::open(&path).context(format!("unable to open {:?}", path))?; - Rope::from_reader(BufReader::new(file))? + let mut doc = Rope::from_reader(BufReader::new(file))?; + // add missing newline at the end of file + if doc.byte(doc.len_bytes() - 1) != b'\n' { + doc.insert_char(doc.len_chars(), '\n'); + } + doc }; let mut doc = Self::new(doc); |