diff --git a/native/src/widget/text_input.rs b/native/src/widget/text_input.rs index c067de77..a302e483 100644 --- a/native/src/widget/text_input.rs +++ b/native/src/widget/text_input.rs @@ -382,6 +382,7 @@ where Event::Keyboard(keyboard::Event::CharacterReceived(c)) if self.state.is_focused && self.state.is_pasting.is_none() + && !self.state.keyboard_modifiers.is_command_pressed() && !c.is_control() => { let mut editor = @@ -395,9 +396,10 @@ where return event::Status::Captured; } Event::Keyboard(keyboard::Event::KeyPressed { - key_code, - modifiers, + key_code, .. }) if self.state.is_focused => { + let modifiers = self.state.keyboard_modifiers; + match key_code { keyboard::KeyCode::Enter => { if let Some(on_submit) = self.on_submit.clone() { @@ -523,7 +525,7 @@ where } } keyboard::KeyCode::V => { - if platform::is_copy_paste_modifier_pressed(modifiers) { + if self.state.keyboard_modifiers.is_command_pressed() { if let Some(clipboard) = clipboard { let content = match self.state.is_pasting.take() { @@ -558,7 +560,7 @@ where } } keyboard::KeyCode::A => { - if platform::is_copy_paste_modifier_pressed(modifiers) { + if self.state.keyboard_modifiers.is_command_pressed() { self.state.cursor.select_all(&self.value); } } @@ -566,6 +568,9 @@ where self.state.is_focused = false; self.state.is_dragging = false; self.state.is_pasting = None; + + self.state.keyboard_modifiers = + keyboard::ModifiersState::default(); } _ => {} } @@ -584,6 +589,11 @@ where return event::Status::Captured; } + Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers)) + if self.state.is_focused => + { + self.state.keyboard_modifiers = modifiers; + } _ => {} } @@ -724,6 +734,7 @@ pub struct State { is_pasting: Option, last_click: Option, cursor: Cursor, + keyboard_modifiers: keyboard::ModifiersState, // TODO: Add stateful horizontal scrolling offset } @@ -745,6 +756,7 @@ impl State { is_pasting: None, last_click: None, cursor: Cursor::default(), + keyboard_modifiers: keyboard::ModifiersState::default(), } } @@ -870,14 +882,4 @@ mod platform { modifiers.control } } - - pub fn is_copy_paste_modifier_pressed( - modifiers: keyboard::ModifiersState, - ) -> bool { - if cfg!(target_os = "macos") { - modifiers.logo - } else { - modifiers.control - } - } }