Skip to main content

CommandExecutor

Struct CommandExecutor 

Source
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

§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

Source

pub fn new(text: &str, viewport_width: usize) -> Self

Create a new command executor

Source

pub fn empty(viewport_width: usize) -> Self

Create an empty command executor

Source

pub fn execute( &mut self, command: Command, ) -> Result<CommandResult, CommandError>

Execute command

Source

pub fn last_text_delta(&self) -> Option<&TextDelta>

Get the structured text delta produced by the last successful execute() call, if any.

Source

pub fn take_last_text_delta(&mut self) -> Option<TextDelta>

Take the structured text delta produced by the last successful execute() call, if any.

Source

pub fn execute_batch( &mut self, commands: Vec<Command>, ) -> Result<Vec<CommandResult>, CommandError>

Batch execute commands (transactional)

Source

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.

Source

pub fn command_history_limit(&self) -> usize

Get the maximum number of commands retained in history.

Source

pub fn set_command_history_limit(&mut self, limit: usize)

Set the maximum number of commands retained in history; 0 disables history recording.

Source

pub fn can_undo(&self) -> bool

Can undo

Source

pub fn can_redo(&self) -> bool

Can redo

Source

pub fn undo_depth(&self) -> usize

Undo stack depth (counted by undo steps; grouped undo may pop multiple steps at once)

Source

pub fn redo_depth(&self) -> usize

Redo stack depth (counted by undo steps)

Source

pub fn redo_branch_count(&self) -> usize

Number of redo branches available at the current history node.

  • In a purely linear history, this is 0 or 1.
  • When you undo and then make a new edit, the previous redo path becomes an alternate branch (undo tree).
Source

pub fn selected_redo_branch_index(&self) -> Option<usize>

Index of the currently selected redo branch at the current node, if any.

Source

pub fn select_redo_branch(&mut self, index: usize) -> Result<(), CommandError>

Select which redo branch EditCommand::Redo will follow from the current node.

Source

pub fn current_change_group(&self) -> Option<usize>

Currently open undo group ID (for insert coalescing only)

Source

pub fn undo_coalescing_timeout(&self) -> Duration

Timeout used when deciding whether adjacent insertion commands remain in one undo group.

Source

pub fn set_undo_coalescing_timeout(&mut self, timeout: Duration)

Configure the insertion coalescing timeout; Duration::ZERO disables time-based merging.

Source

pub fn is_clean(&self) -> bool

Whether current state is at clean point (for dirty tracking)

Source

pub fn mark_clean(&mut self)

Mark current state as clean point (call after saving file)

Source

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.

Source

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.
Source

pub fn editor(&self) -> &EditorCore

Get a reference to the Editor Core

Source

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.

Source

pub fn tab_key_behavior(&self) -> TabKeyBehavior

Get current tab key behavior used by EditCommand::InsertTab.

Source

pub fn set_tab_key_behavior(&mut self, behavior: TabKeyBehavior)

Set tab key behavior used by EditCommand::InsertTab.

Source

pub fn indentation_config(&self) -> &IndentationConfig

Get the current indentation configuration used by EditCommand::InsertNewline when auto_indent=true.

Source

pub fn set_indentation_config(&mut self, config: IndentationConfig)

Replace the indentation configuration used by EditCommand::InsertNewline when auto_indent=true.

Source

pub fn auto_pairs_config(&self) -> &AutoPairsConfig

Get the current auto-pairs configuration.

Source

pub fn set_auto_pairs_config(&mut self, config: AutoPairsConfig)

Replace the auto-pairs configuration.

Source

pub fn set_auto_pairs_enabled(&mut self, enabled: bool)

Enable/disable auto-pairs behavior (convenience wrapper).

Source

pub fn has_active_snippet_session(&self) -> bool

Return true if a snippet session is currently active for this view.

Source

pub fn snippet_session(&self) -> Option<&SnippetSession>

Get the current snippet session (placeholders + navigation), if any.

Source

pub fn set_snippet_session(&mut self, session: Option<SnippetSession>)

Replace the current snippet session.

Source

pub fn preferred_x_cells(&self) -> Option<usize>

Get the sticky x position (in cells) used by visual-row cursor movement.

Source

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.

Source

pub fn line_ending(&self) -> LineEnding

Get the preferred line ending for saving this document.

Source

pub fn set_line_ending(&mut self, line_ending: LineEnding)

Override the preferred line ending for saving this document.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.