From 2cdd90b111bebb3d0780b9268674fa7df434392b Mon Sep 17 00:00:00 2001 From: Tiago Ferreira Date: Thu, 3 Jun 2021 17:39:55 +0200 Subject: [PATCH] Allow alternate shortcuts on Windows (#456) --- egui/src/widgets/text_edit.rs | 2 +- egui_glium/src/lib.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 226cee63..10470000 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -899,7 +899,7 @@ fn on_key_press( }; Some(CCursorPair::one(ccursor)) } - Key::Delete => { + Key::Delete if !(cfg!(target_os = "windows") && modifiers.shift) => { let ccursor = if modifiers.mac_cmd { delete_paragraph_after_cursor(text, galley, cursorp) } else if let Some(cursor) = cursorp.single() { diff --git a/egui_glium/src/lib.rs b/egui_glium/src/lib.rs index 47e90e04..da8ba79d 100644 --- a/egui_glium/src/lib.rs +++ b/egui_glium/src/lib.rs @@ -145,11 +145,11 @@ pub fn input_to_egui( // VirtualKeyCode::Paste etc in winit are broken/untrustworthy, // so we detect these things manually: - if input_state.raw.modifiers.command && keycode == VirtualKeyCode::X { + if is_cut_command(input_state.raw.modifiers, keycode) { input_state.raw.events.push(Event::Cut); - } else if input_state.raw.modifiers.command && keycode == VirtualKeyCode::C { + } else if is_copy_command(input_state.raw.modifiers, keycode) { input_state.raw.events.push(Event::Copy); - } else if input_state.raw.modifiers.command && keycode == VirtualKeyCode::V { + } else if is_paste_command(input_state.raw.modifiers, keycode) { if let Some(clipboard) = clipboard { match clipboard.get_contents() { Ok(contents) => { @@ -247,6 +247,21 @@ fn is_printable_char(chr: char) -> bool { !is_in_private_use_area && !chr.is_ascii_control() } +fn is_cut_command(modifiers: egui::Modifiers, keycode: VirtualKeyCode) -> bool { + (modifiers.command && keycode == VirtualKeyCode::X) + || (cfg!(target_os = "windows") && modifiers.shift && keycode == VirtualKeyCode::Delete) +} + +fn is_copy_command(modifiers: egui::Modifiers, keycode: VirtualKeyCode) -> bool { + (modifiers.command && keycode == VirtualKeyCode::C) + || (cfg!(target_os = "windows") && modifiers.ctrl && keycode == VirtualKeyCode::Insert) +} + +fn is_paste_command(modifiers: egui::Modifiers, keycode: VirtualKeyCode) -> bool { + (modifiers.command && keycode == VirtualKeyCode::V) + || (cfg!(target_os = "windows") && modifiers.shift && keycode == VirtualKeyCode::Insert) +} + pub fn translate_mouse_button(button: glutin::event::MouseButton) -> Option { match button { glutin::event::MouseButton::Left => Some(egui::PointerButton::Primary),