diff options
| author | 2024-01-22 14:30:40 +0100 | |
|---|---|---|
| committer | 2024-01-22 14:30:40 +0100 | |
| commit | b544c908120ae890d26ab52bcae31ce02f877053 (patch) | |
| tree | 6d9304122676503bb788e9340ff48edb990e3bcc /widget/src/text_input | |
| parent | 416e0026c021a8222c925979053d985553f947a6 (diff) | |
| download | iced-b544c908120ae890d26ab52bcae31ce02f877053.tar.gz iced-b544c908120ae890d26ab52bcae31ce02f877053.tar.bz2 iced-b544c908120ae890d26ab52bcae31ce02f877053.zip | |
Fix impossible to type `v` in `TextInput`
Diffstat (limited to '')
| -rw-r--r-- | widget/src/text_input.rs | 63 | 
1 files changed, 29 insertions, 34 deletions
| diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 2cf4ef77..0a7ed014 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -886,42 +886,38 @@ where                          update_cache(state, value);                      } -                    keyboard::Key::Character("v") => { +                    keyboard::Key::Character("v")                          if state.keyboard_modifiers.command() -                            && !state.keyboard_modifiers.alt() -                        { -                            let content = match state.is_pasting.take() { -                                Some(content) => content, -                                None => { -                                    let content: String = clipboard -                                        .read() -                                        .unwrap_or_default() -                                        .chars() -                                        .filter(|c| !c.is_control()) -                                        .collect(); - -                                    Value::new(&content) -                                } -                            }; +                            && !state.keyboard_modifiers.alt() => +                    { +                        let content = match state.is_pasting.take() { +                            Some(content) => content, +                            None => { +                                let content: String = clipboard +                                    .read() +                                    .unwrap_or_default() +                                    .chars() +                                    .filter(|c| !c.is_control()) +                                    .collect(); + +                                Value::new(&content) +                            } +                        }; -                            let mut editor = -                                Editor::new(value, &mut state.cursor); +                        let mut editor = Editor::new(value, &mut state.cursor); -                            editor.paste(content.clone()); +                        editor.paste(content.clone()); -                            let message = if let Some(paste) = &on_paste { -                                (paste)(editor.contents()) -                            } else { -                                (on_input)(editor.contents()) -                            }; -                            shell.publish(message); +                        let message = if let Some(paste) = &on_paste { +                            (paste)(editor.contents()) +                        } else { +                            (on_input)(editor.contents()) +                        }; +                        shell.publish(message); -                            state.is_pasting = Some(content); +                        state.is_pasting = Some(content); -                            update_cache(state, value); -                        } else { -                            state.is_pasting = None; -                        } +                        update_cache(state, value);                      }                      keyboard::Key::Character("a")                          if state.keyboard_modifiers.command() => @@ -945,12 +941,11 @@ where                      }                      _ => {                          if let Some(text) = text { +                            state.is_pasting = None; +                              let c = text.chars().next().unwrap_or_default(); -                            if state.is_pasting.is_none() -                                && !state.keyboard_modifiers.command() -                                && !c.is_control() -                            { +                            if !c.is_control() {                                  let mut editor =                                      Editor::new(value, &mut state.cursor); | 
