@@ -3738,8 +3738,11 @@ fn surround_replace(cx: &mut Context) {
37383738 let transaction = Transaction::change(
37393739 doc.text(),
37403740 change_pos.iter().enumerate().map(|(i, &pos)| {
3741− let ch = if i % 2 == 0 { open } else { close };
3742− (pos, pos + 1, Some(Tendril::from_char(ch)))
3741+ if i % 2 == 0 {
3742+ (pos, pos + 1, Some(Tendril::from_char(open)))
3743+ } else {
3744+ (pos.saturating_sub(1), pos, Some(Tendril::from_char(close)))
3745+ }
37433746 }),
37443747 );
37453748 doc.apply(&transaction, view.id);