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 <https://github.com/emilk/egui/issues/5255>
* [x] I have followed the instructions in the PR template
This commit is contained in:
YgorSouza 2024-10-23 10:56:12 +02:00 committed by GitHub
parent 6add64e144
commit e5c502f21e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 17 deletions

View File

@ -978,23 +978,7 @@ fn events(
break;
}
}
Event::Key {
key: Key::Z,
pressed: true,
modifiers,
..
} if modifiers.matches_logically(Modifiers::COMMAND) => {
if let Some((undo_ccursor_range, undo_txt)) = state
.undoer
.lock()
.undo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned()))
{
text.replace_with(undo_txt);
Some(*undo_ccursor_range)
} else {
None
}
}
Event::Key {
key,
pressed: true,
@ -1016,6 +1000,24 @@ fn events(
}
}
Event::Key {
key: Key::Z,
pressed: true,
modifiers,
..
} if modifiers.matches_logically(Modifiers::COMMAND) => {
if let Some((undo_ccursor_range, undo_txt)) = state
.undoer
.lock()
.undo(&(cursor_range.as_ccursor_range(), text.as_str().to_owned()))
{
text.replace_with(undo_txt);
Some(*undo_ccursor_range)
} else {
None
}
}
Event::Key {
modifiers,
key,