aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorIvan Tham2021-06-07 11:33:55 +0000
committerBlaž Hrastnik2021-06-08 02:38:56 +0000
commit82fdfdc38e8309a36330455e65cc34b7395ac299 (patch)
treee622b84920e6815e730c8352f3270db97817dbf7 /helix-view/src
parentea6667070f05227f5d87eaf977ca0c7ddc982c0a (diff)
Add missing newline to end of file on load
Fix #152
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs7
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);