From 669cdc1fff6b76dfbe276ca184afed1a2dbf9e2e Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Thu, 4 Sep 2025 13:53:02 +0200 Subject: [PATCH] Remove line breaks when pasting into single line TextEdit (#7441) The line breaks are now replaced by spaces, matching the usual behavior of text fields in HTML. * Closes * [x] I have followed the instructions in the PR template Co-authored-by: Lucas Meurer --- crates/egui/src/widgets/text_edit/builder.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index f46776b7..63dec923 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -944,8 +944,12 @@ fn events( Event::Paste(text_to_insert) => { if !text_to_insert.is_empty() { let mut ccursor = text.delete_selected(&cursor_range); - - text.insert_text_at(&mut ccursor, text_to_insert, char_limit); + if multiline { + text.insert_text_at(&mut ccursor, text_to_insert, char_limit); + } else { + let single_line = text_to_insert.replace(['\r', '\n'], " "); + text.insert_text_at(&mut ccursor, &single_line, char_limit); + } Some(CCursorRange::one(ccursor)) } else {