on master help sign in
Add missing newline to end of file on load

Fix #152

commit82fdfdc38e8309a36330455e65cc34b7395ac299 authorIvan Tham <pickfire@riseup.net> dateMon 7 Jun 2021, 19:33 (5 years ago) parentea66670
1 file changed+6−1
helix-view/src/document.rs+6−1
helix-view/src/document.rs+6−1
@@ -147,7 +147,12 @@ impl Document {
147147 Rope::from("\n")
148148 } else {
149149 let file = File::open(&path).context(format!("unable to open {:?}", path))?;
150− Rope::from_reader(BufReader::new(file))?
150+ let mut doc = Rope::from_reader(BufReader::new(file))?;
151+ // add missing newline at the end of file
152+ if doc.byte(doc.len_bytes() - 1) != b'\n' {
153+ doc.insert_char(doc.len_chars(), '\n');
154+ }
155+ doc
151156 };
152157
153158 let mut doc = Self::new(doc);