Skip to content

Commit

Permalink
Implement redo for TextEdit
Browse files Browse the repository at this point in the history
Using shortcuts Ctrl/Cmd + Shift + Z or Ctrl/Cmd + Y, like most
applications.
  • Loading branch information
YgorSouza committed Oct 7, 2023
1 parent a291d84 commit 0cffdfa
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,14 @@ fn events(
ui.ctx().copy_text(text);
}
};
let redo = |text: &mut dyn TextBuffer, state: &mut TextEditState| {
if let Some((redo_ccursor_range, redo_txt)) = state.undoer.lock().redo() {
text.replace(redo_txt.as_str());
Some(redo_ccursor_range)
} else {
None
}
};

let mut any_change = false;

Expand Down Expand Up @@ -985,7 +993,6 @@ fn events(
modifiers,
..
} if modifiers.command && !modifiers.shift => {
// TODO(emilk): redo
if let Some((undo_ccursor_range, undo_txt)) = state
.undoer
.lock()
Expand All @@ -997,6 +1004,18 @@ fn events(
None
}
}
Event::Key {
key: Key::Z,
pressed: true,
modifiers,
..
} if modifiers.command && modifiers.shift => redo(text, state),
Event::Key {
key: Key::Y,
pressed: true,
modifiers,
..
} if modifiers.command && !modifiers.shift => redo(text, state),

Event::Key {
key,
Expand Down

0 comments on commit 0cffdfa

Please sign in to comment.