on master help sign in
Handle line endings correctly in surround
commitb00e9fc227dc2ab1070326f29fbe9626702dfa67 authorGokul Soumya <gokulps15@gmail.com> dateTue 22 Jun 2021, 09:06 (5 years ago) parentb79b5e6
2 files changed+9−11
helix-term/src/commands.rs+9−1 helix-term/src/keymap.rs−10
helix-term/src/commands.rs+9−1
@@ -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 }
helix-term/src/keymap.rs−10
@@ -201,16 +201,6 @@ impl Default for Keymaps {
201201
202202
203203 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, ??
214204 key!('[') => Command::left_bracket_mode,
215205 key!(']') => Command::right_bracket_mode,
216206