on master help sign in
Don't panic on empty document
commit7ef0e2cab6ea3b3b3a4591e0a5882a88925e56c6 authorKevin Sjöberg <mail@kevinsjoberg.com> dateTue 8 Jun 2021, 21:26 (5 years ago) parent35feb61
1 file changed+1−1
helix-view/src/document.rs+1−1
helix-view/src/document.rs+1−1
@@ -149,7 +149,7 @@ impl Document {
149149 let file = File::open(&path).context(format!("unable to open {:?}", path))?;
150150 let mut doc = Rope::from_reader(BufReader::new(file))?;
151151 // add missing newline at the end of file
152− if doc.byte(doc.len_bytes() - 1) != b'\n' {
152+ if doc.len_bytes() == 0 || doc.byte(doc.len_bytes() - 1) != b'\n' {
153153 doc.insert_char(doc.len_chars(), '\n');
154154 }
155155 doc