diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 465f5568..b3ac4cd8 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -730,14 +730,17 @@ impl TextEdit<'_> { } } - // 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. - 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(), - ); + 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); diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png b/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png index ed731869..035f5944 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Code Example.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:322a50c522ba4ac67206332e1d251e121c8c3d5538ca7961880623b20f4933e5 -size 81732 +oid sha256:0466198f14d15f011e16d16efcc28aeaaf80978ea4e46b5d9a1282304c192c4c +size 80907