pub enum Edit {
Insert {
position: Position,
text: String,
},
Delete {
position: Position,
text: String,
},
}Expand description
A single atomic edit operation.
Edits are self-contained and can be inverted for undo/redo. Each edit records the position where it occurred and the text involved.
§Undo/Redo
Use Edit::inverse to get the operation that undoes this edit:
InsertbecomesDeleteDeletebecomesInsert
§Example
use reovim_kernel::api::v1::*;
let insert = Edit::insert(Position::new(0, 5), "Hello");
assert!(insert.is_insert());
assert_eq!(insert.text(), "Hello");
// Get the inverse for undo
let undo = insert.inverse();
assert!(undo.is_delete());
assert_eq!(undo.position(), Position::new(0, 5));Variants§
Implementations§
Source§impl Edit
impl Edit
Sourcepub fn inverse(&self) -> Self
pub fn inverse(&self) -> Self
Get the inverse of this edit (for undo).
Insert becomes Delete and vice versa. The position and text are preserved.
Sourcepub fn transform(&self, against: &Self) -> Self
pub fn transform(&self, against: &Self) -> Self
Transform this edit’s position through another edit.
Returns a new edit with the same text but a position adjusted
to account for the effect of against. This is the OT inclusion
transformation (IT) applied at the edit level.
§Example
use reovim_kernel::api::v1::*;
// An insert at (0,5) transformed through an earlier insert of "abc" at (0,2)
let edit = Edit::insert(Position::new(0, 5), "hello");
let against = Edit::insert(Position::new(0, 2), "abc");
let transformed = edit.transform(&against);
assert_eq!(transformed.position(), Position::new(0, 8)); // 5 + 3
assert_eq!(transformed.text(), "hello"); // text unchangedTrait Implementations§
Source§impl From<Edit> for Transaction
impl From<Edit> for Transaction
impl Eq for Edit
impl StructuralPartialEq for Edit
Auto Trait Implementations§
impl Freeze for Edit
impl RefUnwindSafe for Edit
impl Send for Edit
impl Sync for Edit
impl Unpin for Edit
impl UnsafeUnpin for Edit
impl UnwindSafe for Edit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more