Merge inserts with inserts
This commit is contained in:
parent
730038e0d0
commit
3303a31cc4
7 changed files with 154 additions and 72 deletions
|
|
@ -1,6 +1,8 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use crate::operation_transformation::Operation;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
|
|
@ -21,6 +23,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Debug for MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
{
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("MergeContext")
|
||||
.field("last_operation", &self.last_operation)
|
||||
.field("shift", &self.shift)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
|
|
@ -55,18 +69,24 @@ where
|
|||
threshold_operation: &Operation<T>,
|
||||
) {
|
||||
if let Some(last_operation) = self.last_operation.as_ref() {
|
||||
if threshold_operation.start_index() as i64 + self.shift
|
||||
> last_operation.end_index() as i64
|
||||
if let Operation::Delete {
|
||||
deleted_character_count,
|
||||
..
|
||||
} = last_operation
|
||||
{
|
||||
if let Operation::Delete {
|
||||
deleted_character_count,
|
||||
..
|
||||
} = last_operation
|
||||
if threshold_operation.start_index() as i64 + self.shift
|
||||
> last_operation.end_index() as i64
|
||||
{
|
||||
self.shift -= *deleted_character_count as i64;
|
||||
self.last_operation = None;
|
||||
}
|
||||
} else if let Operation::Insert { .. } = last_operation {
|
||||
if threshold_operation.start_index() as i64 + self.shift
|
||||
- last_operation.len() as i64
|
||||
> last_operation.end_index() as i64
|
||||
{
|
||||
self.last_operation = None;
|
||||
}
|
||||
|
||||
self.last_operation = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue