pub struct CommandHistory { /* private fields */ }Expand description
Manages command history for undo/redo operations.
The history maintains two stacks:
- Undo stack: Commands that can be undone
- Redo stack: Commands that can be redone (cleared when new commands are added)
Thread-safe using Arc<Mutex<>> for interior mutability.
Implementations§
Source§impl CommandHistory
impl CommandHistory
Sourcepub fn push(&self, command: Box<dyn Command>)
pub fn push(&self, command: Box<dyn Command>)
Adds a command to the history.
This clears the redo stack and adds the command to the undo stack. If currently grouping commands, adds to the current group instead.
§Arguments
command- The command to add
Sourcepub fn mark_saved(&self)
pub fn mark_saved(&self)
Marks the current position as the save point.
This is used to track whether the document has been modified since the last save. Call this after successfully saving the file.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Returns whether the document has been modified since the last save.
§Returns
true if there are unsaved changes, false otherwise
Sourcepub fn clear(&self)
pub fn clear(&self)
Clears all history.
This removes all undo/redo commands and resets the save point. Useful when starting a new document or resetting the editor state.
§Example
use iced_code_editor::CommandHistory;
let history = CommandHistory::new(100);
// ... perform some operations ...
// Clear everything when opening a new document
history.clear();
assert_eq!(history.undo_count(), 0);
assert_eq!(history.redo_count(), 0);
assert!(!history.is_modified());Sourcepub fn begin_group(&self, description: &str)
pub fn begin_group(&self, description: &str)
Begins grouping subsequent commands into a composite.
All commands added via push() will be grouped together until
end_group() is called. This is useful for grouping consecutive
typing operations.
§Arguments
description- Description for the composite command
Sourcepub fn end_group(&self)
pub fn end_group(&self)
Ends the current command grouping.
The grouped commands are added to the history as a single composite command. If no commands were grouped, nothing is added.
Sourcepub fn set_max_size(&self, max_size: usize)
pub fn set_max_size(&self, max_size: usize)
Sets the maximum history size.
If the current history exceeds the new size, older commands are removed. This is useful for adjusting memory usage based on system resources.
§Arguments
max_size- New maximum size (number of commands to keep)
§Example
use iced_code_editor::CommandHistory;
let history = CommandHistory::new(100);
// Increase limit for memory-rich environments
history.set_max_size(500);
assert_eq!(history.max_size(), 500);
// Decrease limit for constrained environments
history.set_max_size(50);
assert_eq!(history.max_size(), 50);Sourcepub fn undo_count(&self) -> usize
pub fn undo_count(&self) -> usize
Returns the current number of undo operations available.
This can be useful for displaying history statistics or managing UI state (e.g., enabling/disabling undo buttons).
§Returns
The number of commands that can be undone.
§Example
use iced_code_editor::CommandHistory;
let history = CommandHistory::new(100);
assert_eq!(history.undo_count(), 0);
// After adding commands...
// assert!(history.undo_count() > 0);Sourcepub fn redo_count(&self) -> usize
pub fn redo_count(&self) -> usize
Returns the current number of redo operations available.
This can be useful for displaying history statistics or managing UI state (e.g., enabling/disabling redo buttons).
§Returns
The number of commands that can be redone.
§Example
use iced_code_editor::CommandHistory;
let history = CommandHistory::new(100);
assert_eq!(history.redo_count(), 0);
// After undoing some commands...
// assert!(history.redo_count() > 0);Trait Implementations§
Source§impl Clone for CommandHistory
impl Clone for CommandHistory
Source§fn clone(&self) -> CommandHistory
fn clone(&self) -> CommandHistory
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CommandHistory
impl Debug for CommandHistory
Auto Trait Implementations§
impl Freeze for CommandHistory
impl RefUnwindSafe for CommandHistory
impl Send for CommandHistory
impl Sync for CommandHistory
impl Unpin for CommandHistory
impl UnwindSafe for CommandHistory
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.