From c10b5e9a1e57651cdcfa857b9f5bae8f412a0607 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 16 Jun 2020 22:29:42 -0700 Subject: [PATCH] Correctly initializes `TextArea` Was in a bad state until the first `layout` phase. --- cursive-core/src/views/text_area.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cursive-core/src/views/text_area.rs b/cursive-core/src/views/text_area.rs index bd52719..bcc99c0 100644 --- a/cursive-core/src/views/text_area.rs +++ b/cursive-core/src/views/text_area.rs @@ -63,7 +63,7 @@ new_default!(TextArea); impl TextArea { /// Creates a new, empty TextArea. pub fn new() -> Self { - TextArea { + let mut area = TextArea { content: String::new(), rows: Vec::new(), enabled: true, @@ -71,7 +71,12 @@ impl TextArea { size_cache: None, last_size: Vec2::zero(), cursor: 0, - } + }; + + // Make sure we have valid rows, even for empty text. + area.compute_rows(Vec2::new(1, 1)); + + area } /// Retrieves the content of the view. @@ -382,6 +387,9 @@ impl TextArea { /// Fix a damage located at the cursor. /// /// The only damages are assumed to have occured around the cursor. + /// + /// This is an optimization to not re-compute the entire rows when an + /// insert happened. fn fix_damages(&mut self) { if self.size_cache.is_none() { // If we don't know our size, we'll get a layout command soon.