@@ -3352,7 +3352,15 @@ fn surround_add(cx: &mut Context) {
33523352
33533353 let mut changes = Vec::new();
33543354 for (i, range) in selection.iter().enumerate() {
3355− let (from, to) = (range.from(), range.to() + 1);
3355+ let from = range.from();
3356+ let line = text.char_to_line(range.to());
3357+ let max_to = doc.text().len_chars().saturating_sub(
3358+ get_line_ending(&text.line(line))
3359+ .map(|le| le.len_chars())
3360+ .unwrap_or(0),
3361+ );
3362+ let to = std::cmp::min(range.to() + 1, max_to);
3363+
33563364 changes.push((from, from, Some(Tendril::from_char(open))));
33573365 changes.push((to, to, Some(Tendril::from_char(close))));
33583366 }