mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +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 operational_transform::{OperationSeq, OTError};
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct OperationFactory {
|
pub struct OperationFactory {
|
||||||
|
@ -31,26 +29,31 @@ impl OperationFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, txt: &str, pos: u64) -> Result<OperationSeq, OTError> {
|
pub fn insert(&mut self, txt: &str, pos: u64) -> Result<OperationSeq, OTError> {
|
||||||
info!("inserting {} at {}", txt, pos);
|
|
||||||
let mut out = OperationSeq::default();
|
let mut out = OperationSeq::default();
|
||||||
|
let len = self.content.len() as u64;
|
||||||
out.retain(pos);
|
out.retain(pos);
|
||||||
out.insert(txt);
|
out.insert(txt);
|
||||||
|
out.retain(len - pos);
|
||||||
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(&mut self, pos: u64, count: u64) -> Result<OperationSeq, OTError> {
|
pub fn delete(&mut self, pos: u64, count: u64) -> Result<OperationSeq, OTError> {
|
||||||
let mut out = OperationSeq::default();
|
let mut out = OperationSeq::default();
|
||||||
|
let len = self.content.len() as u64;
|
||||||
out.retain(pos - count);
|
out.retain(pos - count);
|
||||||
out.delete(count);
|
out.delete(count);
|
||||||
|
out.retain(len - pos);
|
||||||
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel(&mut self, pos: u64, count: u64) -> Result<OperationSeq, OTError> {
|
pub fn cancel(&mut self, pos: u64, count: u64) -> Result<OperationSeq, OTError> {
|
||||||
let mut out = OperationSeq::default();
|
let mut out = OperationSeq::default();
|
||||||
|
let len = self.content.len() as u64;
|
||||||
out.retain(pos);
|
out.retain(pos);
|
||||||
out.delete(count);
|
out.delete(count);
|
||||||
|
out.retain(len - (pos+count));
|
||||||
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
self.content = out.apply(&self.content)?; // TODO does applying mutate the OpSeq itself?
|
||||||
Ok(out)
|
Ok(out)
|
||||||
}
|
}
|
||||||
|
@ -59,5 +62,4 @@ impl OperationFactory {
|
||||||
self.content = op.apply(&self.content)?;
|
self.content = op.apply(&self.content)?;
|
||||||
Ok(self.content.clone())
|
Ok(self.content.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue