summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-02-21 13:21:39 +0100
committerLibravatar GitHub <noreply@github.com>2024-02-21 13:21:39 +0100
commit6c00e615b9fb7618c710a3f5d920d00e6b8a258c (patch)
tree14ee593287c216f2b24aba1fe94f695896e634b4
parent56ac21cacbead255c6ae574ed2b7ba2895018c56 (diff)
parent4742f3fef803b22a713a3c9ef8317c84810710e9 (diff)
downloadiced-6c00e615b9fb7618c710a3f5d920d00e6b8a258c.tar.gz
iced-6c00e615b9fb7618c710a3f5d920d00e6b8a258c.tar.bz2
iced-6c00e615b9fb7618c710a3f5d920d00e6b8a258c.zip
Merge pull request #2278 from iced-rs/prioritize-text-insertion
Prioritize text insertion in `TextInput` and `TextEditor`
-rw-r--r--CHANGELOG.md1
-rw-r--r--widget/src/text_editor.rs15
-rw-r--r--widget/src/text_input.rs45
3 files changed, 31 insertions, 30 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8a03638..75ccf988 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Documentation for `horizontal_space` and `vertical_space` helpers. [#2265](https://github.com/iced-rs/iced/pull/2265)
- WebAssembly platform. [#2271](https://github.com/iced-rs/iced/pull/2271)
- Decouple `Key` from `keyboard::Modifiers` and apply them to `text` in `KeyboardInput`. [#2238](https://github.com/iced-rs/iced/pull/2238)
+- Text insertion not being prioritized in `TextInput` and `TextEditor`. [#2278](https://github.com/iced-rs/iced/pull/2278)
Many thanks to...
diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs
index 50f7fabb..79432fe9 100644
--- a/widget/src/text_editor.rs
+++ b/widget/src/text_editor.rs
@@ -686,6 +686,13 @@ impl Update {
text,
..
} if state.is_focused => {
+ if let Some(text) = text {
+ if let Some(c) = text.chars().find(|c| !c.is_control())
+ {
+ 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 +739,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;