summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2020-11-25 19:50:24 +0100
committerLibravatar GitHub <noreply@github.com>2020-11-25 19:50:24 +0100
commit18aa14c7bb47d617927a56421e01b6d30200ba3d (patch)
tree43df8f54d7d619d3a7fdca402788ff4057211b6c
parent87c9df294c79d73ff67a8d9a036cf9ddff24c52f (diff)
parent1d23db1866ee8cf109c3ba10a30ae6324bb9131e (diff)
downloadiced-18aa14c7bb47d617927a56421e01b6d30200ba3d.tar.gz
iced-18aa14c7bb47d617927a56421e01b6d30200ba3d.tar.bz2
iced-18aa14c7bb47d617927a56421e01b6d30200ba3d.zip
Merge pull request #605 from ZakisM/text_input_select_all_fix
This PR fixes a bug with select all (CMD + A on MacOS) when using a text_input.
-rw-r--r--native/src/widget/text_input.rs30
1 files changed, 16 insertions, 14 deletions
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<Value>,
last_click: Option<mouse::Click>,
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
- }
- }
}