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
Delete
Delete text in specified range
Fields
Replace
Replace text in specified range
Fields
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::EndUndoGroupso eligible IME insertions do not merge with normal typing groups.
Fields
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_endare 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 toselection_end.
Fields
InsertText
VSCode-like typing/paste: apply to all carets/selections (primary + secondary)
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)
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.
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: CommentConfigComment 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/endare interpreted in pre-edit character offsets (half-open).additional_editsare 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
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
options: SearchOptionsSearch 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.
Trait Implementations§
Source§impl Clone for EditCommand
impl Clone for EditCommand
Source§fn clone(&self) -> EditCommand
fn clone(&self) -> EditCommand
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EditCommand
impl Debug for EditCommand
impl Eq for EditCommand
Source§impl PartialEq for EditCommand
impl PartialEq for EditCommand
Source§fn eq(&self, other: &EditCommand) -> bool
fn eq(&self, other: &EditCommand) -> bool
self and other values to be equal, and is used by ==.