From e5c502f21e2af26589eb99e36a6667a462ccd210 Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:56:12 +0200 Subject: [PATCH] Fix Ctrl+Shift+Z redo shortcut (#5258) This shortcut was previously triggering the Undo action due to the matches_logically method ignoring the state of the Shift key. This was solved by simply inverting the order of the undo and redo arms, so the undo is not matched if the shortcut corresponds to redo. * Closes * [x] I have followed the instructions in the PR template --- crates/egui/src/widgets/text_edit/builder.rs | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 12e92b904a6..18c653d0291 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -978,39 +978,41 @@ fn events( break; } } + Event::Key { - key: Key::Z, + key, pressed: true, modifiers, .. - } if modifiers.matches_logically(Modifiers::COMMAND) => { - if let Some((undo_ccursor_range, undo_txt)) = state + } if (modifiers.matches_logically(Modifiers::COMMAND) && *key == Key::Y) + || (modifiers.matches_logically(Modifiers::SHIFT | Modifiers::COMMAND) + && *key == Key::Z) => + { + if let Some((redo_ccursor_range, redo_txt)) = state .undoer .lock() - .undo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned())) + .redo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned())) { - text.replace_with(undo_txt); - Some(*undo_ccursor_range) + text.replace_with(redo_txt); + Some(*redo_ccursor_range) } else { None } } + Event::Key { - key, + key: Key::Z, pressed: true, modifiers, .. - } if (modifiers.matches_logically(Modifiers::COMMAND) && *key == Key::Y) - || (modifiers.matches_logically(Modifiers::SHIFT | Modifiers::COMMAND) - && *key == Key::Z) => - { - if let Some((redo_ccursor_range, redo_txt)) = state + } if modifiers.matches_logically(Modifiers::COMMAND) => { + if let Some((undo_ccursor_range, undo_txt)) = state .undoer .lock() - .redo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned())) + .undo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned())) { - text.replace_with(redo_txt); - Some(*redo_ccursor_range) + text.replace_with(undo_txt); + Some(*undo_ccursor_range) } else { None }