aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGokul Soumya2021-06-22 03:36:42 +0000
committerBlaž Hrastnik2021-06-22 05:27:51 +0000
commitb00e9fc227dc2ab1070326f29fbe9626702dfa67 (patch)
treea81f13bef2127cc0359c2fce008ec98882abfe5f
parentb79b5e66f2c4d215aaad224fde139c00bf686d20 (diff)
Handle line endings correctly in surround
-rw-r--r--helix-term/src/commands.rs10
-rw-r--r--helix-term/src/keymap.rs10
2 files changed, 9 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index f1101ad4..6cf99927 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3352,7 +3352,15 @@ fn surround_add(cx: &mut Context) {
let mut changes = Vec::new();
for (i, range) in selection.iter().enumerate() {
- let (from, to) = (range.from(), range.to() + 1);
+ let from = range.from();
+ let line = text.char_to_line(range.to());
+ let max_to = doc.text().len_chars().saturating_sub(
+ get_line_ending(&text.line(line))
+ .map(|le| le.len_chars())
+ .unwrap_or(0),
+ );
+ let to = std::cmp::min(range.to() + 1, max_to);
+
changes.push((from, from, Some(Tendril::from_char(open))));
changes.push((to, to, Some(Tendril::from_char(close))));
}
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index cce3d31f..dabb8adf 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -201,16 +201,6 @@ impl Default for Keymaps {
key!('m') => Command::surround,
- // TODO: refactor into
- // key!('m') => commands::select_to_matching,
- // key!('M') => commands::back_select_to_matching,
- // select mode extend equivalents
-
- // key!('.') => commands::repeat_insert,
- // repeat_select
-
- // TODO: figure out what key to use
- // key!('[') => Command::expand_selection, ??
key!('[') => Command::left_bracket_mode,
key!(']') => Command::right_bracket_mode,