diff --git a/crates/loro-core/src/container/text/text_container.rs b/crates/loro-core/src/container/text/text_container.rs index 3073d925..9fc23671 100644 --- a/crates/loro-core/src/container/text/text_container.rs +++ b/crates/loro-core/src/container/text/text_container.rs @@ -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(), diff --git a/crates/loro-core/src/container/text/tracker.rs b/crates/loro-core/src/container/text/tracker.rs index d6c69787..bed500d8 100644 --- a/crates/loro-core/src/container/text/tracker.rs +++ b/crates/loro-core/src/container/text/tracker.rs @@ -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() { diff --git a/crates/loro-core/src/container/text/tracker/cursor_map.rs b/crates/loro-core/src/container/text/tracker/cursor_map.rs index 3c1a01d4..38e51750 100644 --- a/crates/loro-core/src/container/text/tracker/cursor_map.rs +++ b/crates/loro-core/src/container/text/tracker/cursor_map.rs @@ -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 } }