Merge pull request #3007 from Seppel3210/master
Fix navigation keys on higher layers not working
This commit is contained in:
commit
ec4b925616
2 changed files with 59 additions and 41 deletions
|
|
@ -1142,8 +1142,14 @@ pub enum Binding<Message> {
|
||||||
/// A key press.
|
/// A key press.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct KeyPress {
|
pub struct KeyPress {
|
||||||
/// The key pressed.
|
/// The original key pressed without modifiers applied to it.
|
||||||
|
///
|
||||||
|
/// You should use this key for combinations (e.g. Ctrl+C).
|
||||||
pub key: keyboard::Key,
|
pub key: keyboard::Key,
|
||||||
|
/// The key pressed with modifiers applied to it.
|
||||||
|
///
|
||||||
|
/// You should use this key for any single key bindings (e.g. motions).
|
||||||
|
pub modified_key: keyboard::Key,
|
||||||
/// The state of the keyboard modifiers.
|
/// The state of the keyboard modifiers.
|
||||||
pub modifiers: keyboard::Modifiers,
|
pub modifiers: keyboard::Modifiers,
|
||||||
/// The text produced by the key press.
|
/// The text produced by the key press.
|
||||||
|
|
@ -1157,6 +1163,7 @@ impl<Message> Binding<Message> {
|
||||||
pub fn from_key_press(event: KeyPress) -> Option<Self> {
|
pub fn from_key_press(event: KeyPress) -> Option<Self> {
|
||||||
let KeyPress {
|
let KeyPress {
|
||||||
key,
|
key,
|
||||||
|
modified_key,
|
||||||
modifiers,
|
modifiers,
|
||||||
text,
|
text,
|
||||||
status,
|
status,
|
||||||
|
|
@ -1166,20 +1173,7 @@ impl<Message> Binding<Message> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
let combination = match key.as_ref() {
|
||||||
let key = convert_macos_shortcut(&key, modifiers);
|
|
||||||
|
|
||||||
match key.as_ref() {
|
|
||||||
keyboard::Key::Named(key::Named::Enter) => Some(Self::Enter),
|
|
||||||
keyboard::Key::Named(key::Named::Backspace) => {
|
|
||||||
Some(Self::Backspace)
|
|
||||||
}
|
|
||||||
keyboard::Key::Named(key::Named::Delete)
|
|
||||||
if text.is_none() || text.as_deref() == Some("\u{7f}") =>
|
|
||||||
{
|
|
||||||
Some(Self::Delete)
|
|
||||||
}
|
|
||||||
keyboard::Key::Named(key::Named::Escape) => Some(Self::Unfocus),
|
|
||||||
keyboard::Key::Character("c") if modifiers.command() => {
|
keyboard::Key::Character("c") if modifiers.command() => {
|
||||||
Some(Self::Copy)
|
Some(Self::Copy)
|
||||||
}
|
}
|
||||||
|
|
@ -1194,6 +1188,28 @@ impl<Message> Binding<Message> {
|
||||||
keyboard::Key::Character("a") if modifiers.command() => {
|
keyboard::Key::Character("a") if modifiers.command() => {
|
||||||
Some(Self::SelectAll)
|
Some(Self::SelectAll)
|
||||||
}
|
}
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(binding) = combination {
|
||||||
|
return Some(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let modified_key =
|
||||||
|
convert_macos_shortcut(&key, modifiers).unwrap_or(modified_key);
|
||||||
|
|
||||||
|
match modified_key.as_ref() {
|
||||||
|
keyboard::Key::Named(key::Named::Enter) => Some(Self::Enter),
|
||||||
|
keyboard::Key::Named(key::Named::Backspace) => {
|
||||||
|
Some(Self::Backspace)
|
||||||
|
}
|
||||||
|
keyboard::Key::Named(key::Named::Delete)
|
||||||
|
if text.is_none() || text.as_deref() == Some("\u{7f}") =>
|
||||||
|
{
|
||||||
|
Some(Self::Delete)
|
||||||
|
}
|
||||||
|
keyboard::Key::Named(key::Named::Escape) => Some(Self::Unfocus),
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let c = text.chars().find(|c| !c.is_control())?;
|
let c = text.chars().find(|c| !c.is_control())?;
|
||||||
|
|
@ -1332,6 +1348,7 @@ impl<Message> Update<Message> {
|
||||||
},
|
},
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key,
|
key,
|
||||||
|
modified_key,
|
||||||
modifiers,
|
modifiers,
|
||||||
text,
|
text,
|
||||||
..
|
..
|
||||||
|
|
@ -1346,6 +1363,7 @@ impl<Message> Update<Message> {
|
||||||
|
|
||||||
let key_press = KeyPress {
|
let key_press = KeyPress {
|
||||||
key: key.clone(),
|
key: key.clone(),
|
||||||
|
modified_key: modified_key.clone(),
|
||||||
modifiers: *modifiers,
|
modifiers: *modifiers,
|
||||||
text: text.clone(),
|
text: text.clone(),
|
||||||
status,
|
status,
|
||||||
|
|
@ -1480,28 +1498,20 @@ pub fn default(theme: &Theme, status: Status) -> Style {
|
||||||
pub(crate) fn convert_macos_shortcut(
|
pub(crate) fn convert_macos_shortcut(
|
||||||
key: &keyboard::Key,
|
key: &keyboard::Key,
|
||||||
modifiers: keyboard::Modifiers,
|
modifiers: keyboard::Modifiers,
|
||||||
) -> &keyboard::Key {
|
) -> Option<keyboard::Key> {
|
||||||
if modifiers != keyboard::Modifiers::CTRL {
|
if modifiers != keyboard::Modifiers::CTRL {
|
||||||
return key;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
match key.as_ref() {
|
let key = match key.as_ref() {
|
||||||
keyboard::Key::Character("b") => {
|
keyboard::Key::Character("b") => key::Named::ArrowLeft,
|
||||||
&keyboard::Key::Named(key::Named::ArrowLeft)
|
keyboard::Key::Character("f") => key::Named::ArrowRight,
|
||||||
}
|
keyboard::Key::Character("a") => key::Named::Home,
|
||||||
keyboard::Key::Character("f") => {
|
keyboard::Key::Character("e") => key::Named::End,
|
||||||
&keyboard::Key::Named(key::Named::ArrowRight)
|
keyboard::Key::Character("h") => key::Named::Backspace,
|
||||||
}
|
keyboard::Key::Character("d") => key::Named::Delete,
|
||||||
keyboard::Key::Character("a") => {
|
_ => return None,
|
||||||
&keyboard::Key::Named(key::Named::Home)
|
};
|
||||||
}
|
|
||||||
keyboard::Key::Character("e") => &keyboard::Key::Named(key::Named::End),
|
Some(keyboard::Key::Named(key))
|
||||||
keyboard::Key::Character("h") => {
|
|
||||||
&keyboard::Key::Named(key::Named::Backspace)
|
|
||||||
}
|
|
||||||
keyboard::Key::Character("d") => {
|
|
||||||
&keyboard::Key::Named(key::Named::Delete)
|
|
||||||
}
|
|
||||||
_ => key,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -899,7 +899,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||||
key, text, ..
|
key,
|
||||||
|
text,
|
||||||
|
modified_key,
|
||||||
|
..
|
||||||
}) => {
|
}) => {
|
||||||
let state = state::<Renderer>(tree);
|
let state = state::<Renderer>(tree);
|
||||||
|
|
||||||
|
|
@ -1036,11 +1039,16 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
let key = crate::text_editor::convert_macos_shortcut(
|
let macos_shortcut =
|
||||||
key, modifiers,
|
crate::text_editor::convert_macos_shortcut(
|
||||||
);
|
key, modifiers,
|
||||||
|
);
|
||||||
|
|
||||||
match key.as_ref() {
|
#[cfg(target_os = "macos")]
|
||||||
|
let modified_key =
|
||||||
|
macos_shortcut.as_ref().unwrap_or(modified_key);
|
||||||
|
|
||||||
|
match modified_key.as_ref() {
|
||||||
keyboard::Key::Named(key::Named::Enter) => {
|
keyboard::Key::Named(key::Named::Enter) => {
|
||||||
if let Some(on_submit) = self.on_submit.clone() {
|
if let Some(on_submit) = self.on_submit.clone() {
|
||||||
shell.publish(on_submit);
|
shell.publish(on_submit);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue