on master help sign in
Fix off-by-one in extend_line_above (#3689)

`extend_line_above` (and `extend_line` when facing backwards) skip a line when the current range does not fully cover a line. Before this change: foo b#[|a]#r baz With `extend_line_above` or `extend_line` selected the line above. #[|foo bar]# baz Which is inconsistent with `extend_line_below`. This commit changes the behavior to select the current line when it is not already selected. foo #[|bar]# baz Then further calls of `extend_line_above` extend the selection up line-wise.

commit9c3c6a1c22db065512c5563e9ed1c9dca869c886 authorMichael Davis <mcarsondavis@gmail.com> dateSun 4 Sep 2022, 21:34 (4 years ago) parent20ed8c2
1 file changed+2−2
helix-term/src/commands.rs+2−2
helix-term/src/commands.rs+2−2
@@ -1971,7 +1971,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
19711971 let (start_line, end_line) = range.line_range(text.slice(..));
19721972
19731973 let start = text.line_to_char(match extend {
1974− Extend::Above => start_line.saturating_sub(count),
1974+ Extend::Above => start_line.saturating_sub(count - 1),
19751975 Extend::Below => start_line,
19761976 });
19771977 let end = text.line_to_char(
@@ -1985,7 +1985,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
19851985 // extend to previous/next line if current line is selected
19861986 let (anchor, head) = if range.from() == start && range.to() == end {
19871987 match extend {
1988− Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count + 1))),
1988+ Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count))),
19891989 Extend::Below => (
19901990 start,
19911991 text.line_to_char((end_line + count + 1).min(text.len_lines())),