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.
This commit is contained in:
commit
18aa14c7bb
@ -382,6 +382,7 @@ where
|
|||||||
Event::Keyboard(keyboard::Event::CharacterReceived(c))
|
Event::Keyboard(keyboard::Event::CharacterReceived(c))
|
||||||
if self.state.is_focused
|
if self.state.is_focused
|
||||||
&& self.state.is_pasting.is_none()
|
&& self.state.is_pasting.is_none()
|
||||||
|
&& !self.state.keyboard_modifiers.is_command_pressed()
|
||||||
&& !c.is_control() =>
|
&& !c.is_control() =>
|
||||||
{
|
{
|
||||||
let mut editor =
|
let mut editor =
|
||||||
@ -395,9 +396,10 @@ where
|
|||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key_code,
|
key_code, ..
|
||||||
modifiers,
|
|
||||||
}) if self.state.is_focused => {
|
}) if self.state.is_focused => {
|
||||||
|
let modifiers = self.state.keyboard_modifiers;
|
||||||
|
|
||||||
match key_code {
|
match key_code {
|
||||||
keyboard::KeyCode::Enter => {
|
keyboard::KeyCode::Enter => {
|
||||||
if let Some(on_submit) = self.on_submit.clone() {
|
if let Some(on_submit) = self.on_submit.clone() {
|
||||||
@ -523,7 +525,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::KeyCode::V => {
|
keyboard::KeyCode::V => {
|
||||||
if platform::is_copy_paste_modifier_pressed(modifiers) {
|
if self.state.keyboard_modifiers.is_command_pressed() {
|
||||||
if let Some(clipboard) = clipboard {
|
if let Some(clipboard) = clipboard {
|
||||||
let content = match self.state.is_pasting.take()
|
let content = match self.state.is_pasting.take()
|
||||||
{
|
{
|
||||||
@ -558,7 +560,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::KeyCode::A => {
|
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);
|
self.state.cursor.select_all(&self.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -566,6 +568,9 @@ where
|
|||||||
self.state.is_focused = false;
|
self.state.is_focused = false;
|
||||||
self.state.is_dragging = false;
|
self.state.is_dragging = false;
|
||||||
self.state.is_pasting = None;
|
self.state.is_pasting = None;
|
||||||
|
|
||||||
|
self.state.keyboard_modifiers =
|
||||||
|
keyboard::ModifiersState::default();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -584,6 +589,11 @@ where
|
|||||||
|
|
||||||
return event::Status::Captured;
|
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>,
|
is_pasting: Option<Value>,
|
||||||
last_click: Option<mouse::Click>,
|
last_click: Option<mouse::Click>,
|
||||||
cursor: Cursor,
|
cursor: Cursor,
|
||||||
|
keyboard_modifiers: keyboard::ModifiersState,
|
||||||
// TODO: Add stateful horizontal scrolling offset
|
// TODO: Add stateful horizontal scrolling offset
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,6 +756,7 @@ impl State {
|
|||||||
is_pasting: None,
|
is_pasting: None,
|
||||||
last_click: None,
|
last_click: None,
|
||||||
cursor: Cursor::default(),
|
cursor: Cursor::default(),
|
||||||
|
keyboard_modifiers: keyboard::ModifiersState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,14 +882,4 @@ mod platform {
|
|||||||
modifiers.control
|
modifiers.control
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_copy_paste_modifier_pressed(
|
|
||||||
modifiers: keyboard::ModifiersState,
|
|
||||||
) -> bool {
|
|
||||||
if cfg!(target_os = "macos") {
|
|
||||||
modifiers.logo
|
|
||||||
} else {
|
|
||||||
modifiers.control
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user