diff --git a/crates/vim/src/helix.rs b/crates/vim/src/helix.rs index 2c25ed267df415a63acc5383f3dc6e9befdc2eea..1b39faf1444294c3509cce1f13095e20c204b6a7 100644 --- a/crates/vim/src/helix.rs +++ b/crates/vim/src/helix.rs @@ -714,7 +714,11 @@ impl Vim { // Check if cursor is on empty line by checking first character let line_start_offset = buffer_snapshot.point_to_offset(Point::new(start_row, 0)); let first_char = buffer_snapshot.chars_at(line_start_offset).next(); - let extra_line = if first_char == Some('\n') { 1 } else { 0 }; + let extra_line = if first_char == Some('\n') && selection.is_empty() { + 1 + } else { + 0 + }; let end_row = current_end_row + count as u32 + extra_line; @@ -1335,7 +1339,9 @@ mod test { line one ˇ line three - line four"}, + line four + line five + line six"}, Mode::HelixNormal, ); cx.simulate_keystrokes("x"); @@ -1344,7 +1350,22 @@ mod test { line one « line three - ˇ»line four"}, + ˇ»line four + line five + line six"}, + Mode::HelixNormal, + ); + + // Another x should only select the next line + cx.simulate_keystrokes("x"); + cx.assert_state( + indoc! {" + line one + « + line three + line four + ˇ»line five + line six"}, Mode::HelixNormal, );