Skip to main content

Operator

Trait Operator 

Source
pub trait Operator: Send + Sync {
    // Required methods
    fn id(&self) -> &'static str;
    fn execute(
        &self,
        ctx: &mut OperatorContext<'_>,
        range: Range,
    ) -> Result<(), OperatorError>;

    // Provided methods
    fn is_linewise(&self) -> bool { ... }
    fn is_text_modifying(&self) -> bool { ... }
}
Expand description

Operators execute actions on text ranges.

  • Mechanism (Kernel): Range calculation, text manipulation APIs
  • Policy (Module): What each operator does with the range

§Examples

  • delete - Remove text in range, save to register
  • yank - Copy text in range to register
  • change - Delete text and enter insert mode
  • indent - Increase indentation of lines in range

Required Methods§

Source

fn id(&self) -> &'static str

Unique identifier for this operator.

Source

fn execute( &self, ctx: &mut OperatorContext<'_>, range: Range, ) -> Result<(), OperatorError>

Execute the operator on a range.

§Arguments
  • ctx - Execution context with kernel access
  • range - Text range to operate on
§Errors

Returns OperatorError if the operation fails.

Provided Methods§

Source

fn is_linewise(&self) -> bool

Whether this operator works on whole lines (dd, yy).

Linewise operators extend the range to include full lines.

Source

fn is_text_modifying(&self) -> bool

Whether this operator modifies text.

Used for undo grouping - modifying operators create checkpoints.

Implementors§