vim: Fix out of scope insert line above (#55459)

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #52588 

Release Notes:

- Fixed insert line above out of an scope

Co-authored-by: Yara 🏳️‍⚧️ <git@yara.blue>
This commit is contained in:
EmilioandYara 🏳️‍⚧️ authored and GitHub committed 2026-06-22 14:57:35 +00:00
1 parent 5744486bff
commit d76354bc45
1 file changed
+25 -1
+25 -1
View File
@@ -752,7 +752,17 @@ impl Vim {
let indent = if auto_indent_mode == AutoIndentMode::None {
String::new()
} else {
snapshot.indent_and_comment_for_line(MultiBufferRow(row), cx)
let indent_size = snapshot.indent_size_for_line(MultiBufferRow(row)).len;
let first_char = snapshot.chars_at(Point::new(row, indent_size)).next();
let indent_row = if matches!(first_char, Some('}') | Some(')')) {
snapshot
.prev_non_blank_row(MultiBufferRow(row))
.map(|r| r.0)
.unwrap_or(row)
} else {
row
};
snapshot.indent_and_comment_for_line(MultiBufferRow(indent_row), cx)
};
let start_of_line = Point::new(row, 0);
let edit = (start_of_line..start_of_line, indent + "\n");
@@ -1721,6 +1731,20 @@ mod test {
}"},
Mode::Insert,
);
cx.assert_binding(
"shift-o",
indoc! {"
fn test() {
println!();
ˇ}"},
Mode::Normal,
indoc! {"
fn test() {
println!();
ˇ
}"},
Mode::Insert,
);
}
#[gpui::test]