diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index d79d5e68ceb..3775b270764 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -1,5 +1,6 @@ use std::sync::Arc; +use emath::Rect; use epaint::text::{cursor::CCursor, Galley, LayoutJob}; use crate::{ @@ -562,7 +563,7 @@ impl TextEdit<'_> { Sense::hover() }; let mut response = ui.interact(outer_rect, id, sense); - response.intrinsic_size = Some(Vec2::new(desired_width, desired_outer_size.y)); + response.intrinsic_size = Some(Vec2::new(desired_width, desired_outer_size.y)); // HERE!!! // Don't sent `OutputEvent::Clicked` when a user presses the space bar response.flags -= response::Flags::FAKE_PRIMARY_CLICKED; @@ -722,6 +723,19 @@ impl TextEdit<'_> { } } + if !clip_text { + // Allocate additional space if edits were made this frame that changed the size. This is important so that, + // if there's a ScrollArea, it can properly scroll to the cursor. + // Condition `!clip_text` is important to avoid breaking layout for `TextEdit::singleline` (PR #5640) + let extra_size = galley.size() - rect.size(); + if extra_size.x > 0.0 || extra_size.y > 0.0 { + ui.allocate_rect( + Rect::from_min_size(outer_rect.max, extra_size), + Sense::hover(), + ); + } + } + painter.galley(galley_pos, galley.clone(), text_color); if has_focus {