Fix vim full line operations failing when no trailing newline (#24409)

Closes #24270

Release Notes:

- Fixed an issue where doing line-wise operations in vim mode on the
last line of a file with no trailing newline would not work properly
This commit is contained in:
Ben Kunkle 2025-02-06 17:57:24 -06:00 committed by GitHub
parent 73c487c222
commit 337b9e62d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 79 additions and 17 deletions

View file

@ -162,13 +162,16 @@ impl Vim {
// that line, we will have expanded the start of the selection to ensure it
// contains a newline (so that delete works as expected). We undo that change
// here.
let is_last_line = linewise
&& end.row == buffer.max_row().0
&& buffer.max_point().column > 0
&& start.row < buffer.max_row().0
let max_point = buffer.max_point();
let should_adjust_start = linewise
&& end.row == max_point.row
&& max_point.column > 0
&& start.row < max_point.row
&& start == Point::new(start.row, buffer.line_len(MultiBufferRow(start.row)));
let should_add_newline =
should_adjust_start || (end == max_point && max_point.column > 0 && linewise);
if is_last_line {
if should_adjust_start {
start = Point::new(start.row + 1, 0);
}
@ -179,7 +182,7 @@ impl Vim {
for chunk in buffer.text_for_range(start..end) {
text.push_str(chunk);
}
if is_last_line {
if should_add_newline {
text.push('\n');
}
clipboard_selections.push(ClipboardSelection {