summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--widget/src/text_editor.rs16
-rw-r--r--widget/src/text_input.rs45
2 files changed, 31 insertions, 30 deletions
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,
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;