diff --git a/src/lib/opfactory.rs b/src/lib/opfactory.rs index 190c017..707c951 100644 --- a/src/lib/opfactory.rs +++ b/src/lib/opfactory.rs @@ -1,6 +1,4 @@ use operational_transform::{OperationSeq, OTError}; -use tracing::info; - #[derive(Clone)] pub struct OperationFactory { @@ -31,26 +29,31 @@ impl OperationFactory { } pub fn insert(&mut self, txt: &str, pos: u64) -> Result { - info!("inserting {} at {}", txt, pos); let mut out = OperationSeq::default(); + let len = self.content.len() as u64; out.retain(pos); out.insert(txt); + out.retain(len - pos); self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself? Ok(out) } pub fn delete(&mut self, pos: u64, count: u64) -> Result { let mut out = OperationSeq::default(); + let len = self.content.len() as u64; out.retain(pos - count); out.delete(count); + out.retain(len - pos); self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself? Ok(out) } pub fn cancel(&mut self, pos: u64, count: u64) -> Result { let mut out = OperationSeq::default(); + let len = self.content.len() as u64; out.retain(pos); out.delete(count); + out.retain(len - (pos+count)); self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself? Ok(out) } @@ -59,5 +62,4 @@ impl OperationFactory { self.content = op.apply(&self.content)?; Ok(self.content.clone()) } - }