summaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorKevin Sjöberg2021-06-08 19:26:28 +0000
committerBlaž Hrastnik2021-06-09 00:43:21 +0000
commit7ef0e2cab6ea3b3b3a4591e0a5882a88925e56c6 (patch)
treebbb18cb790009fdc9eddf26b811cf5620df41cf1 /helix-view
parent35feb614b6dab67f7b9660d56888f3724167951a (diff)
Don't panic on empty document
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index c9ea4d7a..87eb34ba 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -149,7 +149,7 @@ impl Document {
let file = File::open(&path).context(format!("unable to open {:?}", path))?;
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' {
+ if doc.len_bytes() == 0 || doc.byte(doc.len_bytes() - 1) != b'\n' {
doc.insert_char(doc.len_chars(), '\n');
}
doc