mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-12-23 05:54:51 +01:00
fix: retain ending chars
This commit is contained in:
parent
ca4f68c5ec
commit
de153c798c
1 changed files with 6 additions and 4 deletions
|
@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue