From ca948588e654561b7418b310ac1f125d8947bec8 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sun, 31 Dec 2017 01:04:33 -0800 Subject: [PATCH] Fixed line-ending detection. --- src/editor/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/editor/mod.rs b/src/editor/mod.rs index b4e38c8..a84b36d 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -98,10 +98,16 @@ impl Editor { let mut line_i: usize = 0; for line in self.buffer.line_iter() { // Get the line ending - let ending = if line.len_chars() > 0 { + let ending = if line.len_chars() == 1 { let g = line.slice(line.len_chars() - 1, line.len_chars()) .graphemes() - .nth(0) + .last() + .unwrap(); + str_to_line_ending(g) + } else if line.len_chars() > 1 { + let g = line.slice(line.len_chars() - 2, line.len_chars()) + .graphemes() + .last() .unwrap(); str_to_line_ending(g) } else {