pub struct UndoManager(/* private fields */);Expand description
UndoManager can be used to undo and redo the changes made to the document with a certain peer.
Notes & pitfalls:
- Local-only: undo/redo affects only local operations from the bound peer; it does not revert
remote edits. For global rollback, use time travel (
checkout/revert_to). - Peer identity: keep the
peer_idstable while anUndoManageris in use. Changing peer IDs can disrupt undo grouping/semantics. - Grouping: you may want to tune the merge interval and exclude origins to group related edits.
Implementations§
Source§impl UndoManager
impl UndoManager
Sourcepub fn undo(&mut self) -> LoroResult<bool>
pub fn undo(&mut self) -> LoroResult<bool>
Undo the last change made by the peer.
Sourcepub fn redo(&mut self) -> LoroResult<bool>
pub fn redo(&mut self) -> LoroResult<bool>
Redo the last change made by the peer.
Sourcepub fn record_new_checkpoint(&mut self) -> LoroResult<()>
pub fn record_new_checkpoint(&mut self) -> LoroResult<()>
Record a new checkpoint.
Sourcepub fn undo_count(&self) -> usize
pub fn undo_count(&self) -> usize
How many times the undo manager can undo.
Sourcepub fn redo_count(&self) -> usize
pub fn redo_count(&self) -> usize
How many times the undo manager can redo.
Sourcepub fn add_exclude_origin_prefix(&mut self, prefix: &str)
pub fn add_exclude_origin_prefix(&mut self, prefix: &str)
If a local event’s origin matches the given prefix, it will not be recorded in the undo stack.
Sourcepub fn set_max_undo_steps(&mut self, size: usize)
pub fn set_max_undo_steps(&mut self, size: usize)
Set the maximum number of undo steps. The default value is 100.
Sourcepub fn set_merge_interval(&mut self, interval: i64)
pub fn set_merge_interval(&mut self, interval: i64)
Set the merge interval in ms. The default value is 0, which means no merge.
Sourcepub fn set_on_push(&mut self, on_push: Option<OnPush>)
pub fn set_on_push(&mut self, on_push: Option<OnPush>)
Set the listener for push events. The listener will be called when a new undo/redo item is pushed into the stack.
Sourcepub fn set_on_pop(&mut self, on_pop: Option<OnPop>)
pub fn set_on_pop(&mut self, on_pop: Option<OnPop>)
Set the listener for pop events. The listener will be called when an undo/redo item is popped from the stack.
Sourcepub fn group_start(&mut self) -> LoroResult<()>
pub fn group_start(&mut self) -> LoroResult<()>
Will start a new group of changes, all subsequent changes will be merged into a new item on the undo stack. If we receive remote changes, we determine wether or not they are conflicting. If the remote changes are conflicting we split the undo item and close the group. If there are no conflict in changed container ids we continue the group merge.
Sourcepub fn group_end(&mut self)
pub fn group_end(&mut self)
Ends the current group, calling UndoManager::undo() after this will undo all changes that occurred during the group.
Sourcepub fn top_undo_meta(&self) -> Option<UndoItemMeta>
pub fn top_undo_meta(&self) -> Option<UndoItemMeta>
Get the metadata of the top undo stack item, if any.
Sourcepub fn top_redo_meta(&self) -> Option<UndoItemMeta>
pub fn top_redo_meta(&self) -> Option<UndoItemMeta>
Get the metadata of the top redo stack item, if any.
Sourcepub fn top_undo_value(&self) -> Option<LoroValue>
pub fn top_undo_value(&self) -> Option<LoroValue>
Get the value associated with the top undo stack item, if any.
Sourcepub fn top_redo_value(&self) -> Option<LoroValue>
pub fn top_redo_value(&self) -> Option<LoroValue>
Get the value associated with the top redo stack item, if any.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UndoManager
impl !RefUnwindSafe for UndoManager
impl Send for UndoManager
impl Sync for UndoManager
impl Unpin for UndoManager
impl !UnwindSafe for UndoManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);