Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR fixes a bug with select all (CMD + A on MacOS) when using a text_input. #605

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions native/src/widget/text_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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() {
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -558,14 +560,17 @@ 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);
}
}
keyboard::KeyCode::Escape => {
self.state.is_focused = false;
self.state.is_dragging = false;
self.state.is_pasting = None;

self.state.keyboard_modifiers =
keyboard::ModifiersState::default();
}
_ => {}
}
Expand All @@ -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;
}
_ => {}
}

Expand Down Expand Up @@ -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
}

Expand All @@ -745,6 +756,7 @@ impl State {
is_pasting: None,
last_click: None,
cursor: Cursor::default(),
keyboard_modifiers: keyboard::ModifiersState::default(),
}
}

Expand Down Expand Up @@ -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
}
}
}