pub struct TextEditor<'a> { /* private fields */ }Expand description
A high-performance, transactional text editor.
It accumulates edits and applies them in a single pass when finish() is called.
It ensures all edits are valid, non-overlapping, and safe according to optional user checks.
Implementations§
Source§impl<'a> TextEditor<'a>
impl<'a> TextEditor<'a>
Sourcepub fn new(text: &'a str) -> Self
pub fn new(text: &'a str) -> Self
Creates a new TextEditor with the default safety threshold (Unsafe - accepts all edits).
Sourcepub fn with_safety(text: &'a str, threshold: Safety) -> Self
pub fn with_safety(text: &'a str, threshold: Safety) -> Self
Creates a new TextEditor with a specific safety threshold.
Edits with a safety level above the threshold will be rejected.
§Example
use mago_text_edit::{TextEditor, Safety};
// Only accept Safe edits
let editor = TextEditor::with_safety("hello", Safety::Safe);Sourcepub fn apply<F>(&mut self, edit: TextEdit, checker: Option<F>) -> ApplyResult
pub fn apply<F>(&mut self, edit: TextEdit, checker: Option<F>) -> ApplyResult
Applies a single edit.
Uses binary search to check for overlaps in O(log N). Rejects edits that exceed the safety threshold.
Sourcepub fn apply_batch<F>(
&mut self,
new_edits: Vec<TextEdit>,
checker: Option<F>,
) -> ApplyResult
pub fn apply_batch<F>( &mut self, new_edits: Vec<TextEdit>, checker: Option<F>, ) -> ApplyResult
Applies a batch of edits atomically.
Either all edits are applied, or none are (if overlap/check/safety fails). If any edit in the batch exceeds the safety threshold, the entire batch is rejected.
Sourcepub fn safety_threshold(&self) -> Safety
pub fn safety_threshold(&self) -> Safety
Returns the current safety threshold.
Trait Implementations§
Source§impl<'a> Clone for TextEditor<'a>
impl<'a> Clone for TextEditor<'a>
Source§fn clone(&self) -> TextEditor<'a>
fn clone(&self) -> TextEditor<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more