Skip to content

Commit

Permalink
Fix Ctrl+Shift+Z redo shortcut
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YgorSouza committed Oct 13, 2024
1 parent 23728e1 commit 8dd57c5
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8dd57c5

Please sign in to comment.