on master help sign in
Fix compose not merging certain changesets correctly.
94f9603Blaž Hrastnik
helix-core/src/selection.rs+5−5
@@ -371,17 +371,17 @@ mod test {
371 assert_eq!(
371 assert_eq!(
372 result.ranges(),
372 result.ranges(),
373 &[
373 &[
374− Range::new(0, 4),
374+ Range::new(0, 3),
375− Range::new(5, 8),
375+ Range::new(5, 7),
376− Range::new(10, 12),
376+ Range::new(10, 11),
377− Range::new(15, 18),
377+ Range::new(15, 17),
378 Range::new(19, 19),
378 Range::new(19, 19),
379 ]
379 ]
380 );
380 );
381
381
382 assert_eq!(
382 assert_eq!(
383 result.fragments(&text.slice(..)).collect::<Vec<_>>(),
383 result.fragments(&text.slice(..)).collect::<Vec<_>>(),
384− &["abcd", "efg", "rs", "xyz", ""]
384+ &["abcd", "efg", "rs", "xyz", "1"]
385 );
385 );
386 }
386 }
387}
387}
helix-core/src/transaction.rs+10−7
@@ -133,10 +133,9 @@ impl ChangeSet {
133 Ordering::Greater => {
133 Ordering::Greater => {
134 // figure out the byte index of the truncated string end
134 // figure out the byte index of the truncated string end
135 let (pos, _) = s.char_indices().nth(j).unwrap();
135 let (pos, _) = s.char_indices().nth(j).unwrap();
136− // calculate the difference
136+ let pos = pos as u32;
137− let to_drop = s.len() - pos;
137+ changes.push(Insert(s.subtendril(0, pos)));
138− s.pop_back(u32::try_from(to_drop).unwrap());
138+ head_a = Some(Insert(s.subtendril(pos, s.len() as u32 - pos)));
139− head_a = Some(Insert(s));
140 head_b = changes_b.next();
139 head_b = changes_b.next();
141 }
140 }
142 }
141 }
@@ -425,7 +424,7 @@ impl Transaction {
425 let len = state.doc.len_chars();
424 let len = state.doc.len_chars();
426 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
425 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
427
426
428− // TODO: verify ranges are ordered and not overlapping.
427+ // TODO: verify ranges are ordered and not overlapping or change will panic.
429
428
430 let mut last = 0;
429 let mut last = 0;
431 for (from, to, tendril) in changes {
430 for (from, to, tendril) in changes {
@@ -445,7 +444,11 @@ impl Transaction {
445 }
444 }
446 last = to;
445 last = to;
447 }
446 }
447+
448+ let span = len - last;
449+ if span > 0 {
448− acc.push(Operation::Retain(len - last));
450+ acc.push(Operation::Retain(span));
451+ }
449
452
450 Self::from(ChangeSet { changes: acc, len })
453 Self::from(ChangeSet { changes: acc, len })
451 }
454 }
@@ -580,7 +583,7 @@ mod test {
580 let transaction = Transaction::change(
583 let transaction = Transaction::change(
581 &state,
584 &state,
582 // (1, 1, None) is a useless 0-width delete
585 // (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(),
584 );
587 );
585 transaction.apply(&mut state);
588 transaction.apply(&mut state);
586 assert_eq!(state.doc, Rope::from_str("hello void! 123"));
589 assert_eq!(state.doc, Rope::from_str("hello void! 123"));