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 execute_batch( &mut self, commands: Vec<Command>, ) -> Result<Vec<CommandResult>, CommandError>

Batch execute commands (transactional)

Source

pub fn get_command_history(&self) -> &[Command]

Get command history

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 current_change_group(&self) -> Option<usize>

Currently open undo group ID (for insert coalescing only)

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 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 Editor Core

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.

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.