From 680e8425c3203d1ad5849b5a854c90582cacdb20 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 21 Feb 2024 13:00:34 +0100 Subject: Prioritize text insertion in `TextInput` and `TextEditor` --- widget/src/text_editor.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'widget/src/text_editor.rs') diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index 50f7fabb..0094419b 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -686,6 +686,14 @@ impl Update { text, .. } if state.is_focused => { + if let Some(text) = text { + if let Some(c) = + text.chars().filter(|c| !c.is_control()).next() + { + return edit(Edit::Insert(c)); + } + } + if let keyboard::Key::Named(named_key) = key.as_ref() { if let Some(motion) = motion(named_key) { let motion = if platform::is_jump_modifier_pressed( @@ -732,13 +740,7 @@ impl Update { { Some(Self::Paste) } - _ => { - let text = text?; - - edit(Edit::Insert( - text.chars().next().unwrap_or_default(), - )) - } + _ => None, } } _ => None, -- cgit