history: Export undos, redos methods, and add clear method. (#527)

This commit is contained in:
Jason Lee 2025-01-03 16:57:00 +08:00 committed by GitHub
parent 8b89b5ba7c
commit 5be03543dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -80,6 +80,22 @@ where
self.undos.push(item);
}
/// Get the undo stack.
pub fn undos(&self) -> &Vec<I> {
&self.undos
}
/// Get the redo stack.
pub fn redos(&self) -> &Vec<I> {
&self.redos
}
/// Clear the undo and redo stacks.
pub fn clear(&mut self) {
self.undos.clear();
self.redos.clear();
}
pub fn undo(&mut self) -> Option<Vec<I>> {
if let Some(first_change) = self.undos.pop() {
let mut changes = vec![first_change.clone()];