From ae94d815e2f7b01d7a83c75544e08ccae70a0722 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 bcd65c7bf..5a9c44062 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -947,8 +947,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 {