Fix opening empty file

This commit is contained in:
Jeremy Soller 2022-10-07 12:20:22 -06:00
parent a36291add7
commit 08d5069327
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE

View file

@ -37,15 +37,19 @@ pub struct TextBuffer<'a> {
impl<'a> TextBuffer<'a> { impl<'a> TextBuffer<'a> {
pub fn new(font_matches: &'a FontMatches, text: &str, font_size: i32, line_width: i32) -> Self { pub fn new(font_matches: &'a FontMatches, text: &str, font_size: i32, line_width: i32) -> Self {
let mut text_lines: Vec<String> = text.lines().map(String::from).collect();
if text_lines.is_empty() {
text_lines.push(String::new());
}
let mut buffer = Self { let mut buffer = Self {
font_matches, font_matches,
text_lines: text.lines().map(String::from).collect(), text_lines,
shape_lines: Vec::new(), shape_lines: Vec::new(),
layout_lines: Vec::new(), layout_lines: Vec::new(),
font_size, font_size,
line_width, line_width,
cursor: TextCursor::default(), cursor: TextCursor::default(),
redraw: true, redraw: false,
}; };
buffer.reshape(); buffer.reshape();
buffer buffer