From ec3200625e9726d944bed96e669a15c30db08338 Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 11 Sep 2024 13:49:41 -0500 Subject: [PATCH] Properly handle empty last line --- src/main.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0651975..37e60ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,21 +233,25 @@ impl FramebufferWriter { } } + fbuf.update_screen(); + let cursor_glyph = glyphs.last().unwrap(); self.cursor_top = cursor_glyph.y as usize - first_line_top_offset + self.next_line_y; self.cursor_bot = cursor_glyph.y as usize - first_line_top_offset + self.next_line_y + cursor_glyph.height; let last_line = self.layout.lines().unwrap().last().unwrap(); - fbuf.update_screen(); - - let first_char_offset = glyphs[last_line.glyph_start].byte_offset; - let last_char_offset = glyphs[last_line.glyph_end -1].byte_offset; - let mut last_char_end = last_char_offset + 1; - while last_char_end < self.out_string.len() && !self.out_string.is_char_boundary(last_char_end) { - last_char_end += 1; - } - let log_line_slice = &self.out_string[first_char_offset..last_char_end]; + let log_line_slice = if last_line.glyph_start == last_line.glyph_end { + "" + } else { + let first_char_offset = glyphs[last_line.glyph_start].byte_offset; + let last_char_offset = glyphs[last_line.glyph_end-1].byte_offset; + let mut last_char_end = last_char_offset + 1; + while last_char_end < self.out_string.len() && !self.out_string.is_char_boundary(last_char_end) { + last_char_end += 1; + } + &self.out_string[first_char_offset..last_char_end] + }; let before_last_height = (last_line.baseline_y - last_line.max_ascent) as usize;