Translate non-latin Key using Physical codes
Co-authored-by: Leonid Onokhov <sopvop@gmail.com> Co-authored-by: edwloef <edwin.frank.loeffler@gmail.com>
This commit is contained in:
parent
3b67106419
commit
e6571d7b70
3 changed files with 103 additions and 20 deletions
|
|
@ -1160,6 +1160,10 @@ pub struct KeyPress {
|
|||
///
|
||||
/// You should use this key for any single key bindings (e.g. motions).
|
||||
pub modified_key: keyboard::Key,
|
||||
/// The physical key pressed.
|
||||
///
|
||||
/// You should use this key for layout-independent bindings.
|
||||
pub physical_key: keyboard::key::Physical,
|
||||
/// The state of the keyboard modifiers.
|
||||
pub modifiers: keyboard::Modifiers,
|
||||
/// The text produced by the key press.
|
||||
|
|
@ -1174,6 +1178,7 @@ impl<Message> Binding<Message> {
|
|||
let KeyPress {
|
||||
key,
|
||||
modified_key,
|
||||
physical_key,
|
||||
modifiers,
|
||||
text,
|
||||
status,
|
||||
|
|
@ -1183,21 +1188,13 @@ impl<Message> Binding<Message> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let combination = match key.as_ref() {
|
||||
keyboard::Key::Character("c") if modifiers.command() => {
|
||||
Some(Self::Copy)
|
||||
}
|
||||
keyboard::Key::Character("x") if modifiers.command() => {
|
||||
Some(Self::Cut)
|
||||
}
|
||||
keyboard::Key::Character("v")
|
||||
if modifiers.command() && !modifiers.alt() =>
|
||||
{
|
||||
let combination = match key.to_latin(physical_key) {
|
||||
Some('c') if modifiers.command() => Some(Self::Copy),
|
||||
Some('x') if modifiers.command() => Some(Self::Cut),
|
||||
Some('v') if modifiers.command() && !modifiers.alt() => {
|
||||
Some(Self::Paste)
|
||||
}
|
||||
keyboard::Key::Character("a") if modifiers.command() => {
|
||||
Some(Self::SelectAll)
|
||||
}
|
||||
Some('a') if modifiers.command() => Some(Self::SelectAll),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
@ -1359,6 +1356,7 @@ impl<Message> Update<Message> {
|
|||
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key,
|
||||
modified_key,
|
||||
physical_key,
|
||||
modifiers,
|
||||
text,
|
||||
..
|
||||
|
|
@ -1374,6 +1372,7 @@ impl<Message> Update<Message> {
|
|||
let key_press = KeyPress {
|
||||
key: key.clone(),
|
||||
modified_key: modified_key.clone(),
|
||||
physical_key: *physical_key,
|
||||
modifiers: *modifiers,
|
||||
text: text.clone(),
|
||||
status,
|
||||
|
|
|
|||
|
|
@ -902,6 +902,7 @@ where
|
|||
key,
|
||||
text,
|
||||
modified_key,
|
||||
physical_key,
|
||||
..
|
||||
}) => {
|
||||
let state = state::<Renderer>(tree);
|
||||
|
|
@ -909,8 +910,8 @@ where
|
|||
if let Some(focus) = &mut state.is_focused {
|
||||
let modifiers = state.keyboard_modifiers;
|
||||
|
||||
match key.as_ref() {
|
||||
keyboard::Key::Character("c")
|
||||
match key.to_latin(*physical_key) {
|
||||
Some('c')
|
||||
if state.keyboard_modifiers.command()
|
||||
&& !self.is_secure =>
|
||||
{
|
||||
|
|
@ -926,7 +927,7 @@ where
|
|||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
keyboard::Key::Character("x")
|
||||
Some('x')
|
||||
if state.keyboard_modifiers.command()
|
||||
&& !self.is_secure =>
|
||||
{
|
||||
|
|
@ -955,7 +956,7 @@ where
|
|||
update_cache(state, &self.value);
|
||||
return;
|
||||
}
|
||||
keyboard::Key::Character("v")
|
||||
Some('v')
|
||||
if state.keyboard_modifiers.command()
|
||||
&& !state.keyboard_modifiers.alt() =>
|
||||
{
|
||||
|
|
@ -994,9 +995,7 @@ where
|
|||
update_cache(state, &self.value);
|
||||
return;
|
||||
}
|
||||
keyboard::Key::Character("a")
|
||||
if state.keyboard_modifiers.command() =>
|
||||
{
|
||||
Some('a') if state.keyboard_modifiers.command() => {
|
||||
let cursor_before = state.cursor;
|
||||
|
||||
state.cursor.select_all(&self.value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue