mirror of
https://github.com/enso-org/enso.git
synced 2024-12-18 17:51:31 +03:00
Mac and Windows shortcuts fixes (https://github.com/enso-org/ide/pull/273)
* Fix pasting on Mac
* Fix AltGraph handling on Windows
Original commit: c077e466b2
This commit is contained in:
parent
81ad282d84
commit
cd31d690b3
@ -131,7 +131,11 @@ impl TextFieldKeyboardFrp {
|
|||||||
text_field.upgrade().for_each(|text_field| {
|
text_field.upgrade().for_each(|text_field| {
|
||||||
if let Key::Character(string) = key {
|
if let Key::Character(string) = key {
|
||||||
let modifiers = &[Key::Control,Key::Alt];
|
let modifiers = &[Key::Control,Key::Alt];
|
||||||
if !modifiers.iter().any(|k| mask.has_key(k)) {
|
let is_modifier = modifiers.iter().any(|k| mask.has_key(k));
|
||||||
|
let is_alt_graph = mask.has_key(&Key::AltGraph);
|
||||||
|
// On Windows AltGraph is emitted as both AltGraph and Ctrl. Therefore we don't
|
||||||
|
// care about modifiers when AltGraph is pressed.
|
||||||
|
if !is_modifier || is_alt_graph {
|
||||||
text_field.write(string);
|
text_field.write(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,18 @@ enum KeyMaskChange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl KeyMaskChange {
|
impl KeyMaskChange {
|
||||||
|
fn on_pressed(key:&Key) -> Self { Self::Set(key.clone()) }
|
||||||
|
fn on_defocus() -> Self { Self::Clear }
|
||||||
|
|
||||||
|
fn on_released(key:&Key) -> Self {
|
||||||
|
match key {
|
||||||
|
// The very special case: pressing CMD on MacOS makes all the keyup events for letters
|
||||||
|
// lost. Therefore for CMD releasing we must clear keymask.
|
||||||
|
Key::Meta => Self::Clear,
|
||||||
|
other => Self::Unset(other.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns copy of given KeyMask with applied change
|
/// Returns copy of given KeyMask with applied change
|
||||||
fn updated_mask(&self, mask:&KeyMask) -> KeyMask {
|
fn updated_mask(&self, mask:&KeyMask) -> KeyMask {
|
||||||
let mut mask = mask.clone();
|
let mut mask = mask.clone();
|
||||||
@ -152,15 +164,13 @@ pub struct Keyboard {
|
|||||||
|
|
||||||
impl Default for Keyboard {
|
impl Default for Keyboard {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let change_set = |key:&Key| KeyMaskChange::Set (key.clone());
|
|
||||||
let change_unset = |key:&Key| KeyMaskChange::Unset(key.clone());
|
|
||||||
frp! {
|
frp! {
|
||||||
keyboard.on_pressed = source();
|
keyboard.on_pressed = source();
|
||||||
keyboard.on_released = source();
|
keyboard.on_released = source();
|
||||||
keyboard.on_defocus = source();
|
keyboard.on_defocus = source();
|
||||||
keyboard.change_set = on_pressed .map(change_set);
|
keyboard.change_set = on_pressed .map(KeyMaskChange::on_pressed);
|
||||||
keyboard.change_unset = on_released.map(change_unset);
|
keyboard.change_unset = on_released.map(KeyMaskChange::on_released);
|
||||||
keyboard.change_clear = on_defocus .map(|()| KeyMaskChange::Clear);
|
keyboard.change_clear = on_defocus .map(|()| KeyMaskChange::on_defocus());
|
||||||
keyboard.change_set_unset = change_set.merge(&change_unset);
|
keyboard.change_set_unset = change_set.merge(&change_unset);
|
||||||
keyboard.change = change_set_unset.merge(&change_clear);
|
keyboard.change = change_set_unset.merge(&change_clear);
|
||||||
keyboard.previous_key_mask = recursive::<KeyMask>();
|
keyboard.previous_key_mask = recursive::<KeyMask>();
|
||||||
|
Loading…
Reference in New Issue
Block a user