Skip to main content

EditorCommand

Trait EditorCommand 

Source
pub trait EditorCommand:
    Debug
    + Send
    + Sync {
    // Required methods
    fn execute(&self, document: &mut EditorDocument) -> Result<CommandResult>;
    fn description(&self) -> &str;

    // Provided methods
    fn modifies_content(&self) -> bool { ... }
    fn memory_usage(&self) -> usize { ... }
}
Expand description

Trait for editor commands that can be executed and undone

All commands implement this trait to provide a consistent interface for execution, undo/redo, and introspection.

§Examples

Creating a custom command:

use ass_editor::{EditorCommand, EditorDocument, CommandResult, Result, Position, Range};

#[derive(Debug)]
struct UppercaseCommand {
    description: String,
}

impl UppercaseCommand {
    fn new() -> Self {
        Self {
            description: "Convert to uppercase".to_string(),
        }
    }
}

impl EditorCommand for UppercaseCommand {
    fn execute(&self, document: &mut EditorDocument) -> Result<CommandResult> {
        let text = document.text().to_uppercase();
        let range = Range::new(Position::new(0), Position::new(document.len()));
        document.replace(range, &text)?;
        Ok(CommandResult::success().with_message("Text converted to uppercase".to_string()))
    }

    fn description(&self) -> &str {
        &self.description
    }
}

Required Methods§

Source

fn execute(&self, document: &mut EditorDocument) -> Result<CommandResult>

Execute the command on the given document

Returns a result indicating success/failure and metadata about the operation for undo/redo tracking.

Source

fn description(&self) -> &str

Get a human-readable description of the command

Provided Methods§

Source

fn modifies_content(&self) -> bool

Check if this command modifies document content

Used to determine if the document should be marked as modified and whether to save undo state.

Source

fn memory_usage(&self) -> usize

Get the estimated memory usage of this command

Used for memory management in undo stacks with limited capacity. Default implementation provides a conservative estimate.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl EditorCommand for AddFontCommand

Source§

impl EditorCommand for AddGraphicCommand

Source§

impl EditorCommand for AdjustKaraokeCommand

Source§

impl EditorCommand for ApplyKaraokeCommand

Source§

impl EditorCommand for ApplyStyleCommand

Source§

impl EditorCommand for BatchCommand

Source§

impl EditorCommand for BatchDeleteEventsCommand

Source§

impl EditorCommand for ClearFontsCommand

Source§

impl EditorCommand for ClearGraphicsCommand

Source§

impl EditorCommand for CloneStyleCommand

Source§

impl EditorCommand for CreateStyleCommand

Source§

impl EditorCommand for DeleteEventCommand

Source§

impl EditorCommand for DeleteScriptInfoCommand

Source§

impl EditorCommand for DeleteStyleCommand

Source§

impl EditorCommand for DeleteTextCommand

Source§

impl EditorCommand for EditStyleCommand

Source§

impl EditorCommand for EventEffectCommand

Source§

impl EditorCommand for GenerateKaraokeCommand

Source§

impl EditorCommand for InsertTagCommand

Source§

impl EditorCommand for InsertTextCommand

Source§

impl EditorCommand for MergeEventsCommand

Source§

impl EditorCommand for ParseTagCommand

Source§

impl EditorCommand for RemoveFontCommand

Source§

impl EditorCommand for RemoveGraphicCommand

Source§

impl EditorCommand for RemoveTagCommand

Source§

impl EditorCommand for ReplaceTagCommand

Source§

impl EditorCommand for ReplaceTextCommand

Source§

impl EditorCommand for SetScriptInfoCommand

Source§

impl EditorCommand for SplitEventCommand

Source§

impl EditorCommand for SplitKaraokeCommand

Source§

impl EditorCommand for TimingAdjustCommand

Source§

impl EditorCommand for ToggleEventTypeCommand

Source§

impl EditorCommand for WrapTagCommand