on master help sign in
Add missing newline to end of file on load
82fdfdcIvan Tham
helix-view/src/document.rs+6−1
@@ -147,7 +147,12 @@ impl Document {
147 Rope::from("\n")
147 Rope::from("\n")
148 } else {
148 } else {
149 let file = File::open(&path).context(format!("unable to open {:?}", path))?;
149 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
151 };
156 };
152
157
153 let mut doc = Self::new(doc);
158 let mut doc = Self::new(doc);