@@ -223,7 +223,9 @@ impl Selection {
224 // TODO: we could do with one vec by removing elements as we mutate
224 // TODO: we could do with one vec by removing elements as we mutate
226− for (i, range) in ranges.into_iter().enumerate() {
228+ for range in ranges.into_iter() {
227 // if previous value exists
229 // if previous value exists
228 if let Some(prev) = result.last_mut() {
230 if let Some(prev) = result.last_mut() {
229 // and we overlap it
231 // and we overlap it
@@ -250,7 +252,8 @@ impl Selection {
253− result.push(range)
255+ result.push(range);
@@ -434,6 +437,22 @@ mod test {
434 .join(",");
437 .join(",");
436 assert_eq!(res, "0/6,6/7,7/8,9/13,13/14");
439 assert_eq!(res, "0/6,6/7,7/8,9/13,13/14");
441+ // it correctly calculates a new primary index
442+ let sel = Selection::new(
443+ smallvec![Range::new(0, 2), Range::new(1, 5), Range::new(4, 7)],
450+ .map(|range| format!("{}/{}", range.anchor, range.head))
451+ .collect::<Vec<String>>()
454+ assert_eq!(res, "0/7");
455+ assert_eq!(sel.primary_index, 0);