Skip to content

Commit 89f6cce

Browse files
the-mikedavisShekhinah Memmel
authored andcommitted
Fix off-by-one in extend_line_above (helix-editor#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.
1 parent ae0063c commit 89f6cce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

helix-term/src/commands.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
19741974
let (start_line, end_line) = range.line_range(text.slice(..));
19751975

19761976
let start = text.line_to_char(match extend {
1977-
Extend::Above => start_line.saturating_sub(count),
1977+
Extend::Above => start_line.saturating_sub(count - 1),
19781978
Extend::Below => start_line,
19791979
});
19801980
let end = text.line_to_char(
@@ -1988,7 +1988,7 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) {
19881988
// extend to previous/next line if current line is selected
19891989
let (anchor, head) = if range.from() == start && range.to() == end {
19901990
match extend {
1991-
Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count + 1))),
1991+
Extend::Above => (end, text.line_to_char(start_line.saturating_sub(count))),
19921992
Extend::Below => (
19931993
start,
19941994
text.line_to_char((end_line + count + 1).min(text.len_lines())),

0 commit comments

Comments
 (0)