From 8dd57c59c25adbd4f125e0c0a7648cb8bb6fe26a Mon Sep 17 00:00:00 2001 From: Ygor Souza Date: Sun, 13 Oct 2024 11:10:31 +0200 Subject: [PATCH] Fix Ctrl+Shift+Z redo shortcut 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 undo and redo arms, so the undo is not matched if the shortcut corresponds to redo. --- 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 f4824a38117..9ff740674a2 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -977,39 +977,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 }