Store tokens instead of text in insert
This commit is contained in:
parent
3391d2c0ec
commit
44f9a44f63
10 changed files with 144 additions and 74 deletions
|
|
@ -1,15 +1,33 @@
|
|||
use crate::operation_transformation::Operation;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct MergeContext {
|
||||
pub last_delete: Option<Operation>,
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
{
|
||||
pub last_delete: Option<Operation<T>>,
|
||||
pub shift: i64,
|
||||
}
|
||||
|
||||
impl MergeContext {
|
||||
impl<T> Default for MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
{
|
||||
fn default() -> Self {
|
||||
MergeContext {
|
||||
last_delete: None,
|
||||
shift: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MergeContext<T>
|
||||
where
|
||||
T: PartialEq + Clone,
|
||||
{
|
||||
/// Replace the last delete operation (if there was one) with a new one while
|
||||
/// applying it to the shift.
|
||||
pub fn replace_delete(&mut self, delete: Option<Operation>) {
|
||||
pub fn replace_delete(&mut self, delete: Option<Operation<T>>) {
|
||||
if let Some(produced_last_delete) = self.last_delete.take() {
|
||||
self.shift -= produced_last_delete.len() as i64;
|
||||
}
|
||||
|
|
@ -19,7 +37,7 @@ impl MergeContext {
|
|||
|
||||
/// Remove the last delete operation (if there was one) in case it is behind the
|
||||
/// threshold operation.
|
||||
pub fn consume_delete_if_behind_operation(&mut self, threshold_operation: &Operation) {
|
||||
pub fn consume_delete_if_behind_operation(&mut self, threshold_operation: &Operation<T>) {
|
||||
match self.last_delete.as_ref() {
|
||||
Some(last_delete)
|
||||
if threshold_operation.start_index() as i64 + self.shift
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue