aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-10-14 02:46:13 +0000
committerBlaž Hrastnik2020-10-14 02:48:01 +0000
commit7fcc6f8f1baab380c3c11a7fa4ca4018f073d52e (patch)
treee3659189d7b9760b29b898cd10af22a121312b82 /helix-core/src
parent94f9603c7490bf1616ecc44af99063f044b4d2a4 (diff)
Fix overlapping (insert | delete) compose
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/transaction.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index d41b68e4..c888de3a 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -109,9 +109,7 @@ impl ChangeSet {
Ordering::Greater => {
// figure out the byte index of the truncated string end
let (pos, _) = s.char_indices().nth(len - j).unwrap();
- // calculate the difference
- let to_drop = s.len() - pos;
- s.pop_back(u32::try_from(to_drop).unwrap());
+ s.pop_front(s.len() as u32 - pos as u32);
head_a = Some(Insert(s));
head_b = changes_b.next();
}
@@ -487,7 +485,7 @@ mod test {
let a = ChangeSet {
changes: vec![
Retain(5),
- Insert("!".into()),
+ Insert(" test!".into()),
Retain(1),
Delete(2),
Insert("abc".into()),
@@ -496,8 +494,8 @@ mod test {
};
let b = ChangeSet {
- changes: vec![Delete(5), Insert("world".into()), Retain(5)],
- len: 9,
+ changes: vec![Delete(10), Insert("world".into()), Retain(5)],
+ len: 15,
};
let mut text = Rope::from("hello xz");