From 82fdfdc38e8309a36330455e65cc34b7395ac299 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 7 Jun 2021 19:33:55 +0800 Subject: Add missing newline to end of file on load Fix #152 --- helix-view/src/document.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'helix-view/src') 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); -- cgit v1.2.3-70-g09d2