diff options
| author | 2024-02-21 13:21:39 +0100 | |
|---|---|---|
| committer | 2024-02-21 13:21:39 +0100 | |
| commit | 6c00e615b9fb7618c710a3f5d920d00e6b8a258c (patch) | |
| tree | 14ee593287c216f2b24aba1fe94f695896e634b4 /widget/src/text_input | |
| parent | 56ac21cacbead255c6ae574ed2b7ba2895018c56 (diff) | |
| parent | 4742f3fef803b22a713a3c9ef8317c84810710e9 (diff) | |
| download | iced-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`
Diffstat (limited to '')
| -rw-r--r-- | widget/src/text_input.rs | 45 | 
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; | 
