From e31b44f1a5d12860283f5dc62646e170217e610a Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:17:02 +0900 Subject: [PATCH] Fix: `Event::Copy` and `Event::Cut` behave as if they select the entire text when there is no selection. (#5115) Fix: `Event::Copy` and `Event::Cut` behave as if they select the entire text when there is no selection. It's unexpected and disconcerting that this behavior occurs when there is no selected area. --- crates/egui/src/widgets/text_edit/builder.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 991ab01c551..3ca36608c47 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -893,16 +893,15 @@ fn events( Event::Copy => { if cursor_range.is_empty() { - copy_if_not_password(ui, text.as_str().to_owned()); + None } else { copy_if_not_password(ui, cursor_range.slice_str(text.as_str()).to_owned()); + None } - None } Event::Cut => { if cursor_range.is_empty() { - copy_if_not_password(ui, text.take()); - Some(CCursorRange::default()) + None } else { copy_if_not_password(ui, cursor_range.slice_str(text.as_str()).to_owned()); Some(CCursorRange::one(text.delete_selected(&cursor_range)))