on master help sign in
Fix compose not merging certain changesets correctly.
commit94f9603c7490bf1616ecc44af99063f044b4d2a4 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 14 Oct 2020, 09:38 (6 years ago) parent989080a
2 files changed+15−12
helix-core/src/selection.rs+5−5 helix-core/src/transaction.rs+10−7
helix-core/src/selection.rs+5−5
@@ -371,17 +371,17 @@ mod test {
371371 assert_eq!(
372372 result.ranges(),
373373 &[
374− Range::new(0, 4),
375− Range::new(5, 8),
376− Range::new(10, 12),
377− Range::new(15, 18),
374+ Range::new(0, 3),
375+ Range::new(5, 7),
376+ Range::new(10, 11),
377+ Range::new(15, 17),
378378 Range::new(19, 19),
379379 ]
380380 );
381381
382382 assert_eq!(
383383 result.fragments(&text.slice(..)).collect::<Vec<_>>(),
384− &["abcd", "efg", "rs", "xyz", ""]
384+ &["abcd", "efg", "rs", "xyz", "1"]
385385 );
386386 }
387387}
helix-core/src/transaction.rs+10−7
@@ -133,10 +133,9 @@ impl ChangeSet {
133133 Ordering::Greater => {
134134 // figure out the byte index of the truncated string end
135135 let (pos, _) = s.char_indices().nth(j).unwrap();
136− // calculate the difference
137− let to_drop = s.len() - pos;
138− s.pop_back(u32::try_from(to_drop).unwrap());
139− head_a = Some(Insert(s));
136+ let pos = pos as u32;
137+ changes.push(Insert(s.subtendril(0, pos)));
138+ head_a = Some(Insert(s.subtendril(pos, s.len() as u32 - pos)));
140139 head_b = changes_b.next();
141140 }
142141 }
@@ -425,7 +424,7 @@ impl Transaction {
425424 let len = state.doc.len_chars();
426425 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
427426
428− // TODO: verify ranges are ordered and not overlapping.
427+ // TODO: verify ranges are ordered and not overlapping or change will panic.
429428
430429 let mut last = 0;
431430 for (from, to, tendril) in changes {
@@ -445,7 +444,11 @@ impl Transaction {
445444 }
446445 last = to;
447446 }
448− acc.push(Operation::Retain(len - last));
447+
448+ let span = len - last;
449+ if span > 0 {
450+ acc.push(Operation::Retain(span));
451+ }
449452
450453 Self::from(ChangeSet { changes: acc, len })
451454 }
@@ -580,7 +583,7 @@ mod test {
580583 let transaction = Transaction::change(
581584 &state,
582585 // (1, 1, None) is a useless 0-width delete
583− vec![(6, 11, Some("void".into())), (12, 17, None), (1, 1, None)].into_iter(),
586+ vec![(1, 1, None), (6, 11, Some("void".into())), (12, 17, None)].into_iter(),
584587 );
585588 transaction.apply(&mut state);
586589 assert_eq!(state.doc, Rope::from_str("hello void! 123"));