From d76354bc45feab251e92cde8fc41f66d524a31ee Mon Sep 17 00:00:00 2001 From: Emilio Date: Mon, 22 Jun 2026 16:57:35 +0200 Subject: [PATCH] vim: Fix out of scope insert line above (#55459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 🏳️‍⚧️ --- crates/vim/src/normal.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/normal.rs b/crates/vim/src/normal.rs index 027324bfab..d91af01a54 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]