Track keyboard modifiers in text_input
This commit is contained in:
parent
d275a4ed32
commit
1d23db1866
@ -382,7 +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.is_logo_pressed
|
&& !self.state.keyboard_modifiers.is_command_pressed()
|
||||||
&& !c.is_control() =>
|
&& !c.is_control() =>
|
||||||
{
|
{
|
||||||
let mut editor =
|
let mut editor =
|
||||||
@ -396,12 +396,9 @@ 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 => {
|
||||||
if platform::is_copy_paste_modifier_pressed(modifiers) {
|
let modifiers = self.state.keyboard_modifiers;
|
||||||
self.state.is_logo_pressed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
match key_code {
|
match key_code {
|
||||||
keyboard::KeyCode::Enter => {
|
keyboard::KeyCode::Enter => {
|
||||||
@ -528,7 +525,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::KeyCode::V => {
|
keyboard::KeyCode::V => {
|
||||||
if self.state.is_logo_pressed {
|
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()
|
||||||
{
|
{
|
||||||
@ -563,15 +560,17 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::KeyCode::A => {
|
keyboard::KeyCode::A => {
|
||||||
if self.state.is_logo_pressed {
|
if self.state.keyboard_modifiers.is_command_pressed() {
|
||||||
self.state.cursor.select_all(&self.value);
|
self.state.cursor.select_all(&self.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard::KeyCode::Escape => {
|
keyboard::KeyCode::Escape => {
|
||||||
self.state.is_focused = false;
|
self.state.is_focused = false;
|
||||||
self.state.is_dragging = false;
|
self.state.is_dragging = false;
|
||||||
self.state.is_logo_pressed = false;
|
|
||||||
self.state.is_pasting = None;
|
self.state.is_pasting = None;
|
||||||
|
|
||||||
|
self.state.keyboard_modifiers =
|
||||||
|
keyboard::ModifiersState::default();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -585,13 +584,16 @@ where
|
|||||||
keyboard::KeyCode::V => {
|
keyboard::KeyCode::V => {
|
||||||
self.state.is_pasting = None;
|
self.state.is_pasting = None;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {}
|
||||||
self.state.is_logo_pressed = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
|
Event::Keyboard(keyboard::Event::ModifiersChanged(modifiers))
|
||||||
|
if self.state.is_focused =>
|
||||||
|
{
|
||||||
|
self.state.keyboard_modifiers = modifiers;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,10 +731,10 @@ where
|
|||||||
pub struct State {
|
pub struct State {
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
is_dragging: bool,
|
is_dragging: bool,
|
||||||
is_logo_pressed: bool,
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,10 +753,10 @@ impl State {
|
|||||||
Self {
|
Self {
|
||||||
is_focused: true,
|
is_focused: true,
|
||||||
is_dragging: false,
|
is_dragging: false,
|
||||||
is_logo_pressed: false,
|
|
||||||
is_pasting: None,
|
is_pasting: None,
|
||||||
last_click: None,
|
last_click: None,
|
||||||
cursor: Cursor::default(),
|
cursor: Cursor::default(),
|
||||||
|
keyboard_modifiers: keyboard::ModifiersState::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,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