Allow alternate shortcuts on Windows (#456)

This commit is contained in:
Tiago Ferreira 2021-06-03 17:39:55 +02:00 committed by GitHub
parent 4964d762a7
commit 2cdd90b111
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -899,7 +899,7 @@ fn on_key_press<S: TextBuffer>(
}; };
Some(CCursorPair::one(ccursor)) Some(CCursorPair::one(ccursor))
} }
Key::Delete => { Key::Delete if !(cfg!(target_os = "windows") && modifiers.shift) => {
let ccursor = if modifiers.mac_cmd { let ccursor = if modifiers.mac_cmd {
delete_paragraph_after_cursor(text, galley, cursorp) delete_paragraph_after_cursor(text, galley, cursorp)
} else if let Some(cursor) = cursorp.single() { } else if let Some(cursor) = cursorp.single() {

View file

@ -145,11 +145,11 @@ pub fn input_to_egui(
// VirtualKeyCode::Paste etc in winit are broken/untrustworthy, // VirtualKeyCode::Paste etc in winit are broken/untrustworthy,
// so we detect these things manually: // 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); 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); 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 { if let Some(clipboard) = clipboard {
match clipboard.get_contents() { match clipboard.get_contents() {
Ok(contents) => { Ok(contents) => {
@ -247,6 +247,21 @@ fn is_printable_char(chr: char) -> bool {
!is_in_private_use_area && !chr.is_ascii_control() !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<egui::PointerButton> { pub fn translate_mouse_button(button: glutin::event::MouseButton) -> Option<egui::PointerButton> {
match button { match button {
glutin::event::MouseButton::Left => Some(egui::PointerButton::Primary), glutin::event::MouseButton::Left => Some(egui::PointerButton::Primary),