pub struct UndoRedoManager {
pub node_stacks: Vec<NodeUndoRedoStack>,
pub content_snapshots: Vec<(ChangesetId, ContentSnapshot)>,
}Expand description
Manager for undo/redo operations across all text nodes
Fields§
§node_stacks: Vec<NodeUndoRedoStack>Per-node undo/redo stacks
Using Vec instead of HashMap for no_std compatibility
content_snapshots: Vec<(ChangesetId, ContentSnapshot)>Styled-content snapshots keyed by TextChangeset.id (see
ContentSnapshot); FIFO-capped at [MAX_CONTENT_SNAPSHOTS].
Implementations§
Source§impl UndoRedoManager
impl UndoRedoManager
Sourcepub fn store_content_snapshot(
&mut self,
id: ChangesetId,
pre: Vec<InlineContent>,
post: Vec<InlineContent>,
)
pub fn store_content_snapshot( &mut self, id: ChangesetId, pre: Vec<InlineContent>, post: Vec<InlineContent>, )
Store the styled pre/post content for a changeset (see ContentSnapshot).
Sourcepub fn get_content_snapshot(&self, id: ChangesetId) -> Option<&ContentSnapshot>
pub fn get_content_snapshot(&self, id: ChangesetId) -> Option<&ContentSnapshot>
Look up the styled snapshot for a changeset id.
Sourcepub fn reinstate_undo(&mut self, operation: UndoableOperation)
pub fn reinstate_undo(&mut self, operation: UndoableOperation)
MWA-C-undo_redo: put a redone operation back on the undo stack
WITHOUT clearing the redo stack (see
NodeUndoRedoStack::push_undo_preserving_redo).
§Panics
Panics if the operation’s changeset target node is None.
Sourcepub fn get_or_create_stack_mut(
&mut self,
node_id: NodeId,
) -> &mut NodeUndoRedoStack
pub fn get_or_create_stack_mut( &mut self, node_id: NodeId, ) -> &mut NodeUndoRedoStack
Get or create a stack for a specific node
§Panics
Panics if the per-node stack list is unexpectedly empty after insertion.
Sourcepub fn get_stack(&self, node_id: NodeId) -> Option<&NodeUndoRedoStack>
pub fn get_stack(&self, node_id: NodeId) -> Option<&NodeUndoRedoStack>
Get a stack for a specific node (immutable)
Sourcepub fn record_operation(
&mut self,
changeset: TextChangeset,
pre_state: NodeStateSnapshot,
)
pub fn record_operation( &mut self, changeset: TextChangeset, pre_state: NodeStateSnapshot, )
Record a text operation (push to undo stack)
This should be called AFTER a changeset has been successfully applied.
The pre_state should contain the node state BEFORE the changeset was applied.
§Arguments
changeset- The changeset that was appliedpre_state- Node state before the changeset
§Panics
Panics if the changeset’s target node is None.
Sourcepub fn peek_undo(&self, node_id: NodeId) -> Option<&UndoableOperation>
pub fn peek_undo(&self, node_id: NodeId) -> Option<&UndoableOperation>
Peek at the next undo operation for a node (without removing it)
This allows user callbacks to inspect what would be undone.
Sourcepub fn peek_redo(&self, node_id: NodeId) -> Option<&UndoableOperation>
pub fn peek_redo(&self, node_id: NodeId) -> Option<&UndoableOperation>
Peek at the next redo operation for a node (without removing it)
This allows user callbacks to inspect what would be redone.
Sourcepub fn pop_undo(&mut self, node_id: NodeId) -> Option<UndoableOperation>
pub fn pop_undo(&mut self, node_id: NodeId) -> Option<UndoableOperation>
Pop an operation from the undo stack
This should be called during undo processing to get the operation to revert. After reverting, the operation should be pushed to the redo stack.
§Returns
Some(operation)- The operation to undoNone- No undo history available
Sourcepub fn pop_redo(&mut self, node_id: NodeId) -> Option<UndoableOperation>
pub fn pop_redo(&mut self, node_id: NodeId) -> Option<UndoableOperation>
Pop an operation from the redo stack
This should be called during redo processing to get the operation to re-apply. After re-applying, the operation should be pushed to the undo stack.
§Returns
Some(operation)- The operation to redoNone- No redo history available
Sourcepub fn push_redo(&mut self, operation: UndoableOperation)
pub fn push_redo(&mut self, operation: UndoableOperation)
Push an operation to the redo stack (after successful undo)
This should be called AFTER an undo operation has been successfully applied.
§Panics
Panics if the operation’s changeset target node is None.
Sourcepub fn push_undo(&mut self, operation: UndoableOperation)
pub fn push_undo(&mut self, operation: UndoableOperation)
Push an operation to the undo stack (after successful redo)
This should be called AFTER a redo operation has been successfully applied.
§Panics
Panics if the operation’s changeset target node is None.
Trait Implementations§
Source§impl Clone for UndoRedoManager
impl Clone for UndoRedoManager
Source§fn clone(&self) -> UndoRedoManager
fn clone(&self) -> UndoRedoManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UndoRedoManager
impl Debug for UndoRedoManager
Source§impl Default for UndoRedoManager
impl Default for UndoRedoManager
Source§fn default() -> UndoRedoManager
fn default() -> UndoRedoManager
Source§impl NodeIdRemap for UndoRedoManager
impl NodeIdRemap for UndoRedoManager
Source§fn remap_node_ids(&mut self, dom: DomId, map: &NodeIdMap)
fn remap_node_ids(&mut self, dom: DomId, map: &NodeIdMap)
Remap the per-node undo/redo stacks after a DOM rebuild.
This is the worst offender of the “stale manager” family: the stacks are
keyed by a bare NodeId, so deleting a PRECEDING SIBLING (which shifts
every following index down by one) used to leave the whole undo history
silently re-attached to a DIFFERENT, still-live element — undo would edit
the wrong node, with no panic and no error.
A stack is attributed to a DOM through the DomNodeId target of its
operations (an empty stack carries no information and is treated as
belonging to the DOM being reconciled). Stacks for unmounted nodes are
dropped, and the content snapshots they referenced are GC’d with them.
Auto Trait Implementations§
impl Freeze for UndoRedoManager
impl RefUnwindSafe for UndoRedoManager
impl Send for UndoRedoManager
impl Sync for UndoRedoManager
impl Unpin for UndoRedoManager
impl UnsafeUnpin for UndoRedoManager
impl UnwindSafe for UndoRedoManager
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more