mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 23:44:55 +01:00
fix: factory delta with abs index and not skips
This commit is contained in:
parent
4e37ca971b
commit
06523b2325
1 changed files with 5 additions and 3 deletions
|
@ -4,13 +4,15 @@ use similar::{TextDiff, ChangeTag};
|
||||||
pub trait OperationFactory {
|
pub trait OperationFactory {
|
||||||
fn content(&self) -> String;
|
fn content(&self) -> String;
|
||||||
|
|
||||||
fn replace(&self, txt: &str) -> OperationSeq { self.delta(0, txt, 0) }
|
fn replace(&self, txt: &str) -> OperationSeq {
|
||||||
|
self.delta(0, txt, self.content().len())
|
||||||
|
}
|
||||||
|
|
||||||
fn delta(&self, skip: usize, txt: &str, tail: usize) -> OperationSeq {
|
fn delta(&self, skip: usize, txt: &str, tail: usize) -> OperationSeq {
|
||||||
let mut out = OperationSeq::default();
|
let mut out = OperationSeq::default();
|
||||||
let content = self.content();
|
let content = self.content();
|
||||||
let tail_index = content.len() - tail;
|
let tail_index = content.len() - tail;
|
||||||
let content_slice = &content[skip..tail_index];
|
let content_slice = &content[skip..tail];
|
||||||
|
|
||||||
if content_slice == txt {
|
if content_slice == txt {
|
||||||
return out; // TODO this won't work, should we return a noop instead?
|
return out; // TODO this won't work, should we return a noop instead?
|
||||||
|
@ -28,7 +30,7 @@ pub trait OperationFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.retain(tail as u64);
|
out.retain(tail_index as u64);
|
||||||
|
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue