Properly handle empty last line

This commit is contained in:
pjht 2024-09-11 13:49:41 -05:00
parent 104da286b1
commit ec3200625e
Signed by: pjht
GPG Key ID: CA239FC6934E6F3A

View File

@ -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;