summaryrefslogtreecommitdiffstats
path: root/widget/src/text_input.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-21 13:00:34 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-02-21 13:00:34 +0100
commit680e8425c3203d1ad5849b5a854c90582cacdb20 (patch)
tree7c3cfbb3f7869dfd72f3055b6eecd7b15a4f1135 /widget/src/text_input.rs
parent56ac21cacbead255c6ae574ed2b7ba2895018c56 (diff)
downloadiced-680e8425c3203d1ad5849b5a854c90582cacdb20.tar.gz
iced-680e8425c3203d1ad5849b5a854c90582cacdb20.tar.bz2
iced-680e8425c3203d1ad5849b5a854c90582cacdb20.zip
Prioritize text insertion in `TextInput` and `TextEditor`
Diffstat (limited to 'widget/src/text_input.rs')
-rw-r--r--widget/src/text_input.rs45
1 files changed, 22 insertions, 23 deletions
diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs
index 72ed1ef3..73346b3d 100644
--- a/widget/src/text_input.rs
+++ b/widget/src/text_input.rs
@@ -762,6 +762,27 @@ where
let modifiers = state.keyboard_modifiers;
focus.updated_at = Instant::now();
+ if let Some(text) = text {
+ state.is_pasting = None;
+
+ let c = text.chars().next().unwrap_or_default();
+
+ if !c.is_control() {
+ let mut editor = Editor::new(value, &mut state.cursor);
+
+ editor.insert(c);
+
+ let message = (on_input)(editor.contents());
+ shell.publish(message);
+
+ focus.updated_at = Instant::now();
+
+ update_cache(state, value);
+
+ return event::Status::Captured;
+ }
+ }
+
match key.as_ref() {
keyboard::Key::Named(key::Named::Enter) => {
if let Some(on_submit) = on_submit.clone() {
@@ -944,29 +965,7 @@ where
) => {
return event::Status::Ignored;
}
- _ => {
- if let Some(text) = text {
- state.is_pasting = None;
-
- let c = text.chars().next().unwrap_or_default();
-
- if !c.is_control() {
- let mut editor =
- Editor::new(value, &mut state.cursor);
-
- editor.insert(c);
-
- let message = (on_input)(editor.contents());
- shell.publish(message);
-
- focus.updated_at = Instant::now();
-
- update_cache(state, value);
-
- return event::Status::Captured;
- }
- }
- }
+ _ => {}
}
return event::Status::Captured;