Fix sizing bug in TextEdit::singleline#5640
Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/5640-master |
|
There are some clippy failures that need fixing |
|
Done. There's still a warning left at |
|
@juancampa you may wanna have a look at this too |
|
The only thing I'm seeing that could be a regression is the frame delay that appears in the video (bottom border disappears for one frame) but I'll test locally to double check |
|
Ok so the border disappearing is because of the TextArea is animating the scroll, which is expected. However, I can still repro the original issue when scroll animation is disabled (using Screenshot.2025-01-27.at.14.13.01.mp4Since This is what I used: 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.
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(),
);
}
} |
|
So, the root cause of the original issue is |
|
Anyway, we need to decide what to do here. If you're both sure that the root cause of the original issue is a flaw in TextEdit, then I can use @juancampa's code in the next commit, if he doesn't object. |
|
The original issue was a bug in When scroll animation is enabled, it works fine, because |
|
Okay, that makes sense. I tried to figure out where the calculation goes wrong, but egui is just too complex and complicated for me. My only suspicion is The solution from @juancampa does work, but to me, it feels more like a workaround. I'll revert to their code and add an if statement for |
|
There is a failing snapshot test that needs eyes on it. If it makes sense, update it with |
|
Hm... I'll check it out tomorrow |
TextEdit::singleline
|
I’ve replaced the "Code Example" snapshot with the version from the CI artifact to fix the test failures. However, I need the CI workflow to run so I can verify that everything is correct. Could you (@emilk or maybe @lucasmerlin?) approve and trigger the workflow when you have time? |
|
Seems like cargo-machete is now failing but that's not your fault 😅 I'll fix that next week |
|
Machete should be fixed by #5745 |
|
Thanks again! |
This PR reverts a change introduced in PR #3660 that caused a regression with `TextEdit::singleline`. The original PR attempted to fix an issue with the cursor in `TextEdit` inside `ScrollArea`, but it did so by adding unnecessary size allocation to `TextEdit`, which breaks the layout when `TextEdit::singleline` is used outside of `ScrollArea`.  The regression introduced by #3660 is more severe, as it completely breaks the layout of applications using `TextEdit::singleline`, as shown in the following issues: * Closes #5500 * Closes #5597 Furthermore, I was unable to reproduce the original bug from PR #3660 in the current version of egui using the following code: ```rust impl eframe::App for MyEguiApp { fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) { ctx.set_debug_on_hover(true); egui::CentralPanel::default().show(ctx, |ui| { ScrollArea::vertical().max_height(100.0).show(ui, |ui| { ui.add(TextEdit::multiline(&mut self.text).hint_text("Enter text here...")) }); }); } } ``` This code attempts to recreate the layout shown in the video from PR #3660, using a `ScrollArea` with limited height and a `TextEdit` inside. However, the cursor hiding issue was not reproducible.  Therefore, I believe the code added in PR #3660 is no longer necessary and only creates more problems. * Closes #5500 * Closes #5597 * [x] I have followed the instructions in the PR template (cherry picked from commit e995c4c)



This PR reverts a change introduced in PR #3660 that caused a regression with
TextEdit::singleline. The original PR attempted to fix an issue with the cursor inTextEditinsideScrollArea, but it did so by adding unnecessary size allocation toTextEdit, which breaks the layout whenTextEdit::singlelineis used outside ofScrollArea.The regression introduced by #3660 is more severe, as it completely breaks the layout of applications using
TextEdit::singleline, as shown in the following issues:Furthermore, I was unable to reproduce the original bug from PR #3660 in the current version of egui using the following code:
This code attempts to recreate the layout shown in the video from PR #3660, using a

ScrollAreawith limited height and aTextEditinside. However, the cursor hiding issue was not reproducible.Therefore, I believe the code added in PR #3660 is no longer necessary and only creates more problems.