@@ -4530,8 +4530,13 @@ fn surround_add(cx: &mut Context) {
45304530 let (view, doc) = current!(cx.editor);
45314531 let selection = doc.selection(view.id);
45324532 let (open, close) = surround::get_pair(ch);
4533+ // The number of chars in get_pair
4534+ let surround_len = 2;
45334535
45344536 let mut changes = Vec::with_capacity(selection.len() * 2);
4537+ let mut ranges = SmallVec::with_capacity(selection.len());
4538+ let mut offs = 0;
4539+
45354540 for range in selection.iter() {
45364541 let mut o = Tendril::new();
45374542 o.push(open);
@@ -4539,9 +4544,19 @@ fn surround_add(cx: &mut Context) {
45394544 c.push(close);
45404545 changes.push((range.from(), range.from(), Some(o)));
45414546 changes.push((range.to(), range.to(), Some(c)));
4547+
4548+ // Add 2 characters to the range to select them
4549+ ranges.push(
4550+ Range::new(offs + range.from(), offs + range.to() + surround_len)
4551+ .with_direction(range.direction()),
4552+ );
4553+
4554+ // Add 2 characters to the offset for the next ranges
4555+ offs += surround_len;
45424556 }
45434557
4544− let transaction = Transaction::change(doc.text(), changes.into_iter());
4558+ let transaction = Transaction::change(doc.text(), changes.into_iter())
4559+ .with_selection(Selection::new(ranges, selection.primary_index()));
45454560 apply_transaction(&transaction, doc, view);
45464561 })
45474562}