aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-06 05:44:33 +0000
committerBlaž Hrastnik2020-10-13 14:13:56 +0000
commiteba5b1ef3329bef35fe387b03bdf2f32cdb34761 (patch)
tree9975a5ac5370363f84fdc5b8c370d59cc4708808 /helix-core/src
parentb765c17896632e27857c7707a9d3d96bd49b8899 (diff)
Fix changeset composition, lengths don't have to match.
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/transaction.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 7871052a..13c0c50f 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -45,10 +45,12 @@ impl ChangeSet {
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
/// returned value will represent the change `docA` → `docC`.
pub fn compose(self, other: ChangeSet) -> Result<Self, ()> {
- if self.len != other.len {
- // length mismatch
- return Err(());
- }
+ // TODO: len before should match len after
+
+ // if self.len != other.len {
+ // // length mismatch
+ // return Err(());
+ // }
let len = self.changes.len();
@@ -477,23 +479,23 @@ mod test {
Insert("!".into()),
Retain(1),
Delete(2),
- Insert("ab".into()),
+ Insert("abc".into()),
],
- len: 7,
+ len: 8,
};
let b = ChangeSet {
- changes: vec![Delete(5), Insert("world".into()), Retain(4)],
- len: 7,
+ changes: vec![Delete(5), Insert("world".into()), Retain(5)],
+ len: 9,
};
let mut text = Rope::from("hello xz");
// should probably return cloned text
- a.compose(b).unwrap().apply(&mut text);
-
- // unimplemented!("{:?}", text);
- // TODO: assert
+ let composed = a.compose(b).unwrap();
+ assert_eq!(composed.len, 8);
+ assert!(composed.apply(&mut text));
+ assert_eq!(text, "world! abc");
}
#[test]