Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

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

Emilio50b4a1c17e49
diff --git a/crates/vim/src/normal.rs b/crates/vim/src/normal.rs
index 027324bfab7..d91af01a542 100644
--- a/crates/vim/src/normal.rs
+++ b/crates/vim/src/normal.rs
@@ -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]