diff options
author | Nathan Vegdahl | 2021-07-20 19:40:58 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-20 19:40:58 +0000 |
commit | 1194fc842a7b91045b6b71f839fc9a9b5a5b19ef (patch) | |
tree | f93e8a04da28732e86c5c938023f08e14addc643 /helix-term/src | |
parent | c9300ec35f1baeab92a5375814b91bb81c66de73 (diff) |
Use new `Range::line_range()` method in more places, as appropriate.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a155e19e..72462741 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1162,15 +1162,12 @@ fn extend_line(cx: &mut Context) { let text = doc.text(); let range = doc.selection(view.id).primary().min_width_1(text.slice(..)); - let start_line = text.char_to_line(range.from()); - let end_line = (text.char_to_line(range.to().saturating_sub(1).max(range.from())) + count) - .min(text.len_lines()); - + let (start_line, end_line) = range.line_range(text.slice(..)); let start = text.line_to_char(start_line); - let mut end = text.line_to_char(end_line); + let mut end = text.line_to_char((end_line + count).min(text.len_lines())); if range.from() == start && range.to() == end { - end = text.line_to_char((end_line + 1).min(text.len_lines())); + end = text.line_to_char((end_line + count + 1).min(text.len_lines())); } doc.set_selection(view.id, Selection::single(start, end)); @@ -1184,12 +1181,9 @@ fn extend_to_line_bounds(cx: &mut Context) { doc.selection(view.id).clone().transform(|range| { let text = doc.text(); - let start_line = text.char_to_line(range.from()); - let end_line = (text.char_to_line(range.to().saturating_sub(1).max(range.from())) + 1) - .min(text.len_lines()); - + let (start_line, end_line) = range.line_range(text.slice(..)); let start = text.line_to_char(start_line); - let end = text.line_to_char(end_line); + let end = text.line_to_char((end_line + 1).min(text.len_lines())); if range.anchor <= range.head { Range::new(start, end) @@ -3111,8 +3105,8 @@ fn paste_impl( (Paste::Before, true) => text.line_to_char(text.char_to_line(range.from())), // paste linewise after (Paste::After, true) => { - let idx = range.to().saturating_sub(1).max(range.from()); - text.line_to_char((text.char_to_line(idx) + 1).min(text.len_lines())) + let line = range.line_range(text.slice(..)).1; + text.line_to_char((line + 1).min(text.len_lines())) } // paste insert (Paste::Before, false) => range.from(), |