fix: get cursors at id span bug

This commit is contained in:
Zixuan Chen 2022-10-22 18:25:16 +08:00
parent b0572016a0
commit 7154b5e8fe
3 changed files with 8 additions and 5 deletions

View file

@ -192,11 +192,7 @@ impl Container for TextContainer {
// stage 2
// TODO: reduce computations
let path = store.find_path(&self.head, &latest_head);
debug_log!("BEFORE CHECKOUT");
dbg!(&self.tracker);
self.tracker.checkout(self.vv.clone());
debug_log!("AFTER CHECKOUT");
dbg!(&self.tracker);
debug_log!(
"[Stage 2]: Iterate path: {} from {} => {}",
format!("{:?}", path.right).red(),

View file

@ -184,6 +184,7 @@ impl Tracker {
let IdSpanQueryResult { inserts, deletes } = self
.id_to_cursor
.get_cursors_at_id_span(IdSpan::new(*span.0, span.1.start, span.1.end));
for (id, delete) in deletes {
assert!(span.contains_id(id));
for deleted_span in delete.iter() {

View file

@ -260,7 +260,7 @@ impl CursorMap {
Marker::Delete(del) => {
if span.intersect(&id.to_span(del.len())) {
let from = (span.counter.min() - id.counter).max(0);
let to = (span.counter.max() - id.counter).min(del.len() as Counter);
let to = (span.counter.end() - id.counter).min(del.len() as Counter);
if to - from > 0 {
deletes.push((id.inc(from), del.slice(from as usize, to as usize)));
}
@ -269,6 +269,12 @@ impl CursorMap {
}
}
if cfg!(test) {
let insert_len: usize = inserts.iter().map(|x| x.1.len).sum();
let del_len: usize = deletes.iter().map(|x| x.1.len()).sum();
assert_eq!(insert_len + del_len, span.len());
}
IdSpanQueryResult { inserts, deletes }
}