fix: retain ending chars

This commit is contained in:
əlemi 2023-04-11 14:24:53 +02:00
parent ca4f68c5ec
commit de153c798c

View file

@ -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<OperationSeq, OTError> {
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<OperationSeq, OTError> {
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<OperationSeq, OTError> {
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())
}
}