Compact diffs
This commit is contained in:
parent
331e264399
commit
8b8733c1e3
1 changed files with 119 additions and 171 deletions
|
|
@ -251,70 +251,6 @@ impl Operation {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Merges the operation with another operation that is consequtive to this operation.
|
||||
/// The other operation must start where this operation ends.
|
||||
/// The two operations must be of the same type, otherwise panics.
|
||||
pub fn extend(self, other: &Self) -> Self {
|
||||
match (self, other) {
|
||||
(
|
||||
Operation::Insert { index, text },
|
||||
Operation::Insert {
|
||||
text: other_text, ..
|
||||
},
|
||||
) => {
|
||||
let end_index = index + text.chars().count();
|
||||
debug_assert!(
|
||||
end_index == other.start_index(),
|
||||
"Cannot merge non-consequtive inserts with index {} and {}",
|
||||
end_index,
|
||||
other.start_index()
|
||||
);
|
||||
|
||||
Operation::Insert {
|
||||
index,
|
||||
text: text + other_text,
|
||||
}
|
||||
}
|
||||
(
|
||||
Operation::Delete {
|
||||
index,
|
||||
deleted_character_count,
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
deleted_text,
|
||||
},
|
||||
Operation::Delete {
|
||||
index: other_index,
|
||||
deleted_character_count: other_deleted_character_count,
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
deleted_text: other_deleted_text,
|
||||
},
|
||||
) => {
|
||||
debug_assert!(
|
||||
index == *other_index,
|
||||
"Cannot merge non-consequtive deletes",
|
||||
);
|
||||
|
||||
Operation::Delete {
|
||||
index,
|
||||
deleted_character_count: deleted_character_count
|
||||
+ other_deleted_character_count,
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
deleted_text: deleted_text
|
||||
.into_iter()
|
||||
.flat_map(|t1| other_deleted_text.as_ref().map(|t2| t1 + t2).into_iter())
|
||||
.last(),
|
||||
}
|
||||
}
|
||||
(this, other) => panic!(
|
||||
"Cannot merge operations of different type: {:?} and {:?}",
|
||||
&this, &other
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Operation {
|
||||
|
|
|
|||
Loading…
Reference in a new issue