@@ -41,11 +41,26 @@ impl ChangeSet {
42 // TODO: from iter
42 // TODO: from iter
45+ fn len_after(&self) -> usize {
49+ for change in &self.changes {
51+ Retain(i) => len += i,
52+ Insert(s) => len += s.chars().count(),
44 /// Combine two changesets together.
59 /// Combine two changesets together.
45 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
60 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
46 /// returned value will represent the change `docA` → `docC`.
61 /// returned value will represent the change `docA` → `docC`.
47 pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
62 pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
48− // TODO: len before b should match len after a
63+ debug_assert!(self.len_after() == other.len);
50 let len = self.changes.len();
65 let len = self.changes.len();
@@ -182,10 +197,7 @@ impl ChangeSet {
182 /// Returns a new changeset that reverts this one. Useful for `undo` implementation.
197 /// Returns a new changeset that reverts this one. Useful for `undo` implementation.
183 /// The document parameter expects the original document before this change was applied.
198 /// The document parameter expects the original document before this change was applied.
184 pub fn invert(&self, original_doc: &Rope) -> Self {
199 pub fn invert(&self, original_doc: &Rope) -> Self {
185− if original_doc.len_chars() != self.len {
200+ assert!(original_doc.len_chars() == self.len);
186− panic!("Document length mismatch");
190 let mut changes = Vec::with_capacity(self.changes.len());
202 let mut changes = Vec::with_capacity(self.changes.len());
191 let mut pos = 0;
203 let mut pos = 0;