Skip to main content

EditCommand

Enum EditCommand 

Source
pub enum EditCommand {
Show 32 variants Insert { offset: usize, text: String, }, Delete { start: usize, length: usize, }, Replace { start: usize, length: usize, text: String, }, ReplaceCoalescingUndo { start: usize, length: usize, text: String, }, ReplaceCoalescingUndoWithSelection { start: usize, length: usize, text: String, selection_start: usize, selection_end: usize, }, InsertText { text: String, }, TypeChar { ch: char, }, InsertTab, InsertNewline { auto_indent: bool, }, Indent, Outdent, DuplicateLines, DeleteLines, MoveLinesUp, MoveLinesDown, JoinLines, SplitLine, ToggleComment { config: CommentConfig, }, ApplyTextEdits { edits: Vec<TextEditSpec>, }, ApplySnippet { start: usize, end: usize, snippet: String, additional_edits: Vec<TextEditSpec>, }, DeleteToPrevTabStop, DeleteGraphemeBack, DeleteGraphemeForward, DeleteWordBack, DeleteWordForward, Backspace, DeleteForward, Undo, Redo, EndUndoGroup, ReplaceCurrent { query: String, replacement: String, options: SearchOptions, }, ReplaceAll { query: String, replacement: String, options: SearchOptions, },
}
Expand description

Text editing commands

Variants§

§

Insert

Insert text at the specified position

Fields

§offset: usize

Character offset to insert at.

§text: String

Text to insert.

§

Delete

Delete text in specified range

Fields

§start: usize

Character offset of the deletion start.

§length: usize

Length of the deletion in characters.

§

Replace

Replace text in specified range

Fields

§start: usize

Character offset of the replacement start.

§length: usize

Length of the replaced range in characters.

§text: String

Replacement text.

§

ReplaceCoalescingUndo

Replace text in specified range, requesting undo coalescing when the edit is eligible.

This is primarily useful for UI layers that need to keep IME composition updates and the final commit in one explicitly delimited undo group.

Notes:

  • Normal typing coalescing is intentionally limited to pure adjacent insertions without newlines.
  • This explicit composition path may coalesce replacements only when each update replaces the exact range inserted by the previous update and the selection state is continuous.
  • The caller is expected to explicitly delimit boundaries via EditCommand::EndUndoGroup so eligible IME insertions do not merge with normal typing groups.

Fields

§start: usize

Character offset of the replacement start.

§length: usize

Length of the replaced range in characters.

§text: String

Replacement text.

§

ReplaceCoalescingUndoWithSelection

Like EditCommand::ReplaceCoalescingUndo, but also sets the primary selection/caret.

This is primarily useful for IME composition updates where the host provides a selection range inside the marked (preedit) string while keeping composition updates in one explicitly delimited undo group.

Notes:

  • selection_start/selection_end are post-edit character offsets (Unicode scalar indices) in the resulting document.
  • If selection_start == selection_end, the selection is cleared and the caret is moved to selection_end.

Fields

§start: usize

Character offset of the replacement start.

§length: usize

Length of the replaced range in characters.

§text: String

Replacement text.

§selection_start: usize

Selection start (post-edit) in character offsets.

§selection_end: usize

Selection end (post-edit) in character offsets.

§

InsertText

VSCode-like typing/paste: apply to all carets/selections (primary + secondary)

Fields

§text: String

Text to insert/replace at each selection/caret.

§

TypeChar

Type a single character using auto-pairs rules (if enabled).

This is intended for UI “typing” paths (not paste). It supports:

  • auto-close pairs ((), {}, [], quotes)
  • skip over existing closing delimiters
  • wrap selection with pairs (optional)

Fields

§ch: char

The typed character.

§

InsertTab

Insert a tab at each caret (or replace each selection), using the current tab settings.

  • If TabKeyBehavior::Tab, inserts '\t'.
  • If TabKeyBehavior::Spaces, inserts spaces up to the next tab stop.
§

InsertNewline

Insert a newline at each caret (or replace each selection).

If auto_indent is true, the inserted newline is followed by the leading whitespace prefix of the current logical line.

Fields

§auto_indent: bool

Whether to auto-indent the new line.

§

Indent

Indent the selected lines (or the current line for an empty selection).

§

Outdent

Outdent the selected lines (or the current line for an empty selection).

§

DuplicateLines

Duplicate the selected line(s) (or the current line for an empty selection).

This is a line-based operation and will act on all carets/selections (primary + secondary), including rectangular selections.

§

DeleteLines

Delete the selected line(s) (or the current line for an empty selection).

This is a line-based operation and will act on all carets/selections (primary + secondary), including rectangular selections.

§

MoveLinesUp

Move the selected line(s) up by one line.

This is a line-based operation and will act on all carets/selections (primary + secondary), including rectangular selections.

§

MoveLinesDown

Move the selected line(s) down by one line.

This is a line-based operation and will act on all carets/selections (primary + secondary), including rectangular selections.

§

JoinLines

Join the current line with the next line (for each caret/selection).

If multiple carets/selections exist, joins are applied from bottom to top to keep offsets stable.

§

SplitLine

Split the current line at each caret (or replace each selection) by inserting a newline.

This is a convenience alias for EditCommand::InsertNewline with auto_indent: false.

§

ToggleComment

Toggle comments for the selected line(s) or selection ranges, using a language-provided comment configuration.

Fields

§config: CommentConfig

Comment tokens/config for the current language (data-driven).

§

ApplyTextEdits

Apply a batch of text edits as a single undoable step.

  • Edits are interpreted in pre-edit character offsets.
  • Edits must be non-overlapping; they are applied in descending offset order internally.

Fields

§edits: Vec<TextEditSpec>

The edit list (character offsets, half-open).

§

ApplySnippet

Apply a snippet-shaped insert as a single undoable step.

This is primarily intended for LSP completion items with insertTextFormat == 2.

  • start/end are interpreted in pre-edit character offsets (half-open).
  • additional_edits are applied in the same undo step (also in pre-edit coordinates).
  • The snippet is expanded (placeholders removed / defaults inserted), and the first placeholder (lowest index) is selected for navigation via CursorCommand::SnippetNextPlaceholder / CursorCommand::SnippetPrevPlaceholder.

Fields

§start: usize

Inclusive start character offset.

§end: usize

Exclusive end character offset.

§snippet: String

Snippet text in TextMate / VS Code snippet syntax.

§additional_edits: Vec<TextEditSpec>

Additional text edits (LSP additionalTextEdits), in pre-edit coordinates.

§

DeleteToPrevTabStop

Smart backspace: if the caret is in leading whitespace, delete back to the previous tab stop.

Otherwise, behaves like EditCommand::Backspace.

§

DeleteGraphemeBack

Delete the previous Unicode grapheme cluster (UAX #29) for each caret/selection.

§

DeleteGraphemeForward

Delete the next Unicode grapheme cluster (UAX #29) for each caret/selection.

§

DeleteWordBack

Delete back to the previous Unicode word boundary (UAX #29) for each caret/selection.

§

DeleteWordForward

Delete forward to the next Unicode word boundary (UAX #29) for each caret/selection.

§

Backspace

Backspace-like deletion: delete selection(s) if any, otherwise delete 1 char before each caret.

§

DeleteForward

Delete key-like deletion: delete selection(s) if any, otherwise delete 1 char after each caret.

§

Undo

Undo last edit operation (supports grouping)

§

Redo

Redo last undone operation (supports grouping)

§

EndUndoGroup

Explicitly end the current undo group (for idle or external boundaries)

§

ReplaceCurrent

Replace the current occurrence of query (based on selection/caret) with replacement.

  • Honors options (case sensitivity / whole-word / regex).
  • Treated as a single undoable edit.

Fields

§query: String

Search query.

§replacement: String

Replacement text.

§options: SearchOptions

Search options (case sensitivity, whole-word, regex).

§

ReplaceAll

Replace all occurrences of query with replacement.

  • Honors options (case sensitivity / whole-word / regex).
  • Treated as a single undoable edit.

Fields

§query: String

Search query.

§replacement: String

Replacement text.

§options: SearchOptions

Search options (case sensitivity, whole-word, regex).

Trait Implementations§

Source§

impl Clone for EditCommand

Source§

fn clone(&self) -> EditCommand

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EditCommand

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for EditCommand

Source§

impl PartialEq for EditCommand

Source§

fn eq(&self, other: &EditCommand) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for EditCommand

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.