on master help sign in
Handle line endings correctly in surround
b00e9fcGokul Soumya
helix-term/src/commands.rs+9−1
@@ -3352,7 +3352,15 @@ fn surround_add(cx: &mut Context) {
3352
3352
3353 let mut changes = Vec::new();
3353 let mut changes = Vec::new();
3354 for (i, range) in selection.iter().enumerate() {
3354 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+
3356 changes.push((from, from, Some(Tendril::from_char(open))));
3364 changes.push((from, from, Some(Tendril::from_char(open))));
3357 changes.push((to, to, Some(Tendril::from_char(close))));
3365 changes.push((to, to, Some(Tendril::from_char(close))));
3358 }
3366 }
helix-term/src/keymap.rs−10
@@ -201,16 +201,6 @@ impl Default for Keymaps {
201
201
202
202
203 key!('m') => Command::surround,
203 key!('m') => Command::surround,
204− // TODO: refactor into
205− // key!('m') => commands::select_to_matching,
206− // key!('M') => commands::back_select_to_matching,
207− // select mode extend equivalents
208−
209− // key!('.') => commands::repeat_insert,
210− // repeat_select
211−
212− // TODO: figure out what key to use
213− // key!('[') => Command::expand_selection, ??
214 key!('[') => Command::left_bracket_mode,
204 key!('[') => Command::left_bracket_mode,
215 key!(']') => Command::right_bracket_mode,
205 key!(']') => Command::right_bracket_mode,
216
206