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 end of paragraph deletion when there's no blank lines (#29490)

Dinof2813f60ed7a
diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs
index 331d7897f68..f582fea1665 100644
--- a/crates/vim/src/motion.rs
+++ b/crates/vim/src/motion.rs
@@ -1309,6 +1309,16 @@ impl Motion {
end_point.row -= 1;
end_point.column = 0;
selection.end = map.clip_point(map.next_line_boundary(end_point).1, Bias::Left);
+ } else if let Motion::EndOfParagraph = self {
+ // Special case: When using the "}" motion, it's possible
+ // that there's no blank lines after the paragraph the
+ // cursor is currently on.
+ // In this situation the `end_point.column` value will be
+ // greater than 0, so the selection doesn't actually end on
+ // the first character of a blank line. In that case, we'll
+ // want to move one column to the right, to actually include
+ // all characters of the last non-blank line.
+ selection.end = movement::saturating_right(map, selection.end)
}
}
} else if kind == MotionKind::Inclusive {
diff --git a/crates/vim/src/normal/delete.rs b/crates/vim/src/normal/delete.rs
index 583e775fc67..f52d9bebe05 100644
--- a/crates/vim/src/normal/delete.rs
+++ b/crates/vim/src/normal/delete.rs
@@ -351,6 +351,29 @@ mod test {
.assert_matches();
}
+ #[gpui::test]
+ async fn test_delete_end_of_paragraph(cx: &mut gpui::TestAppContext) {
+ let mut cx = NeovimBackedTestContext::new(cx).await;
+ cx.simulate(
+ "d }",
+ indoc! {"
+ ˇhello world.
+
+ hello world."},
+ )
+ .await
+ .assert_matches();
+
+ cx.simulate(
+ "d }",
+ indoc! {"
+ ˇhello world.
+ hello world."},
+ )
+ .await
+ .assert_matches();
+ }
+
#[gpui::test]
async fn test_delete_0(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
diff --git a/crates/vim/test_data/test_delete_end_of_paragraph.json b/crates/vim/test_data/test_delete_end_of_paragraph.json
new file mode 100644
index 00000000000..860fed7a68d
--- /dev/null
+++ b/crates/vim/test_data/test_delete_end_of_paragraph.json
@@ -0,0 +1,8 @@
+{"Put":{"state":"ˇhello world.\n\nhello world."}}
+{"Key":"d"}
+{"Key":"}"}
+{"Get":{"state":"ˇ\nhello world.","mode":"Normal"}}
+{"Put":{"state":"ˇhello world.\nhello world."}}
+{"Key":"d"}
+{"Key":"}"}
+{"Get":{"state":"ˇ","mode":"Normal"}}