pub struct CommandExecutor { /* private fields */ }Expand description
Command executor
CommandExecutor is the main interface for the editor, responsible for:
- Execute various editor commands
- Maintain command history
- Handle errors and exceptions
- Ensure editor state consistency
§Command Types
EditCommand- Text insertion, deletion, replacementCursorCommand- Cursor movement, selection operationsViewCommand- Viewport management and scroll controlStyleCommand- Style and folding management
§Example
use editor_core::{CommandExecutor, Command, EditCommand, CursorCommand, Position};
let mut executor = CommandExecutor::empty(80);
// Insert text
executor.execute(Command::Edit(EditCommand::Insert {
offset: 0,
text: "fn main() {}".to_string(),
})).unwrap();
// Move cursor
executor.execute(Command::Cursor(CursorCommand::MoveTo {
line: 0,
column: 3,
})).unwrap();
assert_eq!(executor.editor().cursor_position(), Position::new(0, 3));Implementations§
Source§impl CommandExecutor
impl CommandExecutor
Sourcepub fn execute(
&mut self,
command: Command,
) -> Result<CommandResult, CommandError>
pub fn execute( &mut self, command: Command, ) -> Result<CommandResult, CommandError>
Execute command
Sourcepub fn last_text_delta(&self) -> Option<&TextDelta>
pub fn last_text_delta(&self) -> Option<&TextDelta>
Get the structured text delta produced by the last successful execute() call, if any.
Sourcepub fn take_last_text_delta(&mut self) -> Option<TextDelta>
pub fn take_last_text_delta(&mut self) -> Option<TextDelta>
Take the structured text delta produced by the last successful execute() call, if any.
Sourcepub fn execute_batch(
&mut self,
commands: Vec<Command>,
) -> Result<Vec<CommandResult>, CommandError>
pub fn execute_batch( &mut self, commands: Vec<Command>, ) -> Result<Vec<CommandResult>, CommandError>
Batch execute commands (transactional)
Sourcepub fn get_command_history(&self) -> &[Command]
pub fn get_command_history(&self) -> &[Command]
Get the bounded command history.
Large text payloads are stored as summaries so this debug-oriented history does not keep another full copy of pasted or inserted text.
Sourcepub fn command_history_limit(&self) -> usize
pub fn command_history_limit(&self) -> usize
Get the maximum number of commands retained in history.
Sourcepub fn set_command_history_limit(&mut self, limit: usize)
pub fn set_command_history_limit(&mut self, limit: usize)
Set the maximum number of commands retained in history; 0 disables history recording.
Sourcepub fn undo_depth(&self) -> usize
pub fn undo_depth(&self) -> usize
Undo stack depth (counted by undo steps; grouped undo may pop multiple steps at once)
Sourcepub fn redo_depth(&self) -> usize
pub fn redo_depth(&self) -> usize
Redo stack depth (counted by undo steps)
Sourcepub fn redo_branch_count(&self) -> usize
pub fn redo_branch_count(&self) -> usize
Number of redo branches available at the current history node.
- In a purely linear history, this is
0or1. - When you undo and then make a new edit, the previous redo path becomes an alternate branch (undo tree).
Sourcepub fn selected_redo_branch_index(&self) -> Option<usize>
pub fn selected_redo_branch_index(&self) -> Option<usize>
Index of the currently selected redo branch at the current node, if any.
Sourcepub fn select_redo_branch(&mut self, index: usize) -> Result<(), CommandError>
pub fn select_redo_branch(&mut self, index: usize) -> Result<(), CommandError>
Select which redo branch EditCommand::Redo will follow from the current node.
Sourcepub fn current_change_group(&self) -> Option<usize>
pub fn current_change_group(&self) -> Option<usize>
Currently open undo group ID (for insert coalescing only)
Sourcepub fn undo_coalescing_timeout(&self) -> Duration
pub fn undo_coalescing_timeout(&self) -> Duration
Timeout used when deciding whether adjacent insertion commands remain in one undo group.
Sourcepub fn set_undo_coalescing_timeout(&mut self, timeout: Duration)
pub fn set_undo_coalescing_timeout(&mut self, timeout: Duration)
Configure the insertion coalescing timeout; Duration::ZERO disables time-based merging.
Sourcepub fn mark_clean(&mut self)
pub fn mark_clean(&mut self)
Mark current state as clean point (call after saving file)
Sourcepub fn undo_history_snapshot(&self) -> UndoHistorySnapshot
pub fn undo_history_snapshot(&self) -> UndoHistorySnapshot
Capture a persistable snapshot of the undo/redo history for this document.
Callers are expected to persist the current document text separately.
Sourcepub fn restore_undo_history(
&mut self,
snapshot: UndoHistorySnapshot,
) -> Result<(), UndoHistoryRestoreError>
pub fn restore_undo_history( &mut self, snapshot: UndoHistorySnapshot, ) -> Result<(), UndoHistoryRestoreError>
Restore a previously captured UndoHistorySnapshot.
Notes:
- This does not modify the current document text.
- Callers should only restore a snapshot into the same text it was captured from.
Sourcepub fn editor(&self) -> &EditorCore
pub fn editor(&self) -> &EditorCore
Get a reference to the Editor Core
Sourcepub fn editor_mut(&mut self) -> &mut EditorCore
pub fn editor_mut(&mut self) -> &mut EditorCore
Get a mutable reference to the field-private Editor Core.
Prefer execute for command-driven mutations that must keep text, layout,
cursor, selection, folding, style, and undo state synchronized. This accessor is intended for
advanced callers that need to invoke public EditorCore methods directly; it does not
expose private fields.
Sourcepub fn tab_key_behavior(&self) -> TabKeyBehavior
pub fn tab_key_behavior(&self) -> TabKeyBehavior
Get current tab key behavior used by EditCommand::InsertTab.
Sourcepub fn set_tab_key_behavior(&mut self, behavior: TabKeyBehavior)
pub fn set_tab_key_behavior(&mut self, behavior: TabKeyBehavior)
Set tab key behavior used by EditCommand::InsertTab.
Sourcepub fn indentation_config(&self) -> &IndentationConfig
pub fn indentation_config(&self) -> &IndentationConfig
Get the current indentation configuration used by EditCommand::InsertNewline when
auto_indent=true.
Sourcepub fn set_indentation_config(&mut self, config: IndentationConfig)
pub fn set_indentation_config(&mut self, config: IndentationConfig)
Replace the indentation configuration used by EditCommand::InsertNewline when
auto_indent=true.
Sourcepub fn auto_pairs_config(&self) -> &AutoPairsConfig
pub fn auto_pairs_config(&self) -> &AutoPairsConfig
Get the current auto-pairs configuration.
Sourcepub fn set_auto_pairs_config(&mut self, config: AutoPairsConfig)
pub fn set_auto_pairs_config(&mut self, config: AutoPairsConfig)
Replace the auto-pairs configuration.
Sourcepub fn set_auto_pairs_enabled(&mut self, enabled: bool)
pub fn set_auto_pairs_enabled(&mut self, enabled: bool)
Enable/disable auto-pairs behavior (convenience wrapper).
Sourcepub fn has_active_snippet_session(&self) -> bool
pub fn has_active_snippet_session(&self) -> bool
Return true if a snippet session is currently active for this view.
Sourcepub fn snippet_session(&self) -> Option<&SnippetSession>
pub fn snippet_session(&self) -> Option<&SnippetSession>
Get the current snippet session (placeholders + navigation), if any.
Sourcepub fn set_snippet_session(&mut self, session: Option<SnippetSession>)
pub fn set_snippet_session(&mut self, session: Option<SnippetSession>)
Replace the current snippet session.
Sourcepub fn preferred_x_cells(&self) -> Option<usize>
pub fn preferred_x_cells(&self) -> Option<usize>
Get the sticky x position (in cells) used by visual-row cursor movement.
Sourcepub fn set_preferred_x_cells(&mut self, preferred_x_cells: Option<usize>)
pub fn set_preferred_x_cells(&mut self, preferred_x_cells: Option<usize>)
Set the sticky x position (in cells) used by visual-row cursor movement.
Sourcepub fn line_ending(&self) -> LineEnding
pub fn line_ending(&self) -> LineEnding
Get the preferred line ending for saving this document.
Sourcepub fn set_line_ending(&mut self, line_ending: LineEnding)
pub fn set_line_ending(&mut self, line_ending: LineEnding)
Override the preferred line ending for saving this document.