Merge pull request #2278 from iced-rs/prioritize-text-insertion
Prioritize text insertion in `TextInput` and `TextEditor`
This commit is contained in:
commit
6c00e615b9
3 changed files with 31 additions and 30 deletions
|
|
@ -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)
|
- 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)
|
- 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)
|
- 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...
|
Many thanks to...
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -686,6 +686,13 @@ impl Update {
|
||||||
text,
|
text,
|
||||||
..
|
..
|
||||||
} if state.is_focused => {
|
} 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 keyboard::Key::Named(named_key) = key.as_ref() {
|
||||||
if let Some(motion) = motion(named_key) {
|
if let Some(motion) = motion(named_key) {
|
||||||
let motion = if platform::is_jump_modifier_pressed(
|
let motion = if platform::is_jump_modifier_pressed(
|
||||||
|
|
@ -732,13 +739,7 @@ impl Update {
|
||||||
{
|
{
|
||||||
Some(Self::Paste)
|
Some(Self::Paste)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => None,
|
||||||
let text = text?;
|
|
||||||
|
|
||||||
edit(Edit::Insert(
|
|
||||||
text.chars().next().unwrap_or_default(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
||||||
|
|
@ -762,6 +762,27 @@ where
|
||||||
let modifiers = state.keyboard_modifiers;
|
let modifiers = state.keyboard_modifiers;
|
||||||
focus.updated_at = Instant::now();
|
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() {
|
match key.as_ref() {
|
||||||
keyboard::Key::Named(key::Named::Enter) => {
|
keyboard::Key::Named(key::Named::Enter) => {
|
||||||
if let Some(on_submit) = on_submit.clone() {
|
if let Some(on_submit) = on_submit.clone() {
|
||||||
|
|
@ -944,29 +965,7 @@ where
|
||||||
) => {
|
) => {
|
||||||
return event::Status::Ignored;
|
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;
|
return event::Status::Captured;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue