@@ -445,36 +445,36 @@ pub mod util {
445445 // the tabstop closest to the range simply replaces `head` while anchor remains in place
446446 // the remaining tabstops receive their own single-width cursor
447447 if range.head < range.anchor {
448− let first_tabstop = tabstop_anchor + tabstops[0].1;
448+ let last_idx = tabstops.len() - 1;
449+ let last_tabstop = tabstop_anchor + tabstops[last_idx].0;
449450
450451 // if selection is forward but was moved to the right it is
451452 // contained entirely in the replacement text, just do a point
452453 // selection (fallback below)
453− if range.anchor >= first_tabstop {
454− let range = Range::new(range.anchor, first_tabstop);
454+ if range.anchor > last_tabstop {
455+ let range = Range::new(range.anchor, last_tabstop);
455456 mapped_selection.push(range);
456− let rem_tabstops = tabstops[1..]
457+ let rem_tabstops = tabstops[..last_idx]
457458 .iter()
458− .map(|tabstop| Range::point(tabstop_anchor + tabstop.1));
459+ .map(|tabstop| Range::point(tabstop_anchor + tabstop.0));
459460 mapped_selection.extend(rem_tabstops);
460461 continue;
461462 }
462463 } else {
463− let last_idx = tabstops.len() - 1;
464− let last_tabstop = tabstop_anchor + tabstops[last_idx].1;
464+ let first_tabstop = tabstop_anchor + tabstops[0].0;
465465
466466 // if selection is forward but was moved to the right it is
467467 // contained entirely in the replacement text, just do a point
468468 // selection (fallback below)
469− if range.anchor <= last_tabstop {
469+ if range.anchor < first_tabstop {
470470 // we can't properly compute the the next grapheme
471471 // here because the transaction hasn't been applied yet
472472 // that is not a problem because the range gets grapheme aligned anyway
473473 // tough so just adding one will always cause head to be grapheme
474474 // aligned correctly when applied to the document
475− let range = Range::new(range.anchor, last_tabstop + 1);
475+ let range = Range::new(range.anchor, first_tabstop + 1);
476476 mapped_selection.push(range);
477− let rem_tabstops = tabstops[..last_idx]
477+ let rem_tabstops = tabstops[1..]
478478 .iter()
479479 .map(|tabstop| Range::point(tabstop_anchor + tabstop.0));
480480 mapped_selection.extend(rem_tabstops);