From de153c798cbe12866401fd485cc795e8a37043e9 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 11 Apr 2023 14:24:53 +0200 Subject: [PATCH] fix: retain ending chars --- src/lib/opfactory.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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()) } - }