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 space forward bug with non-ASCII characters at EOL (#27860)

Peter Finnbda33ec43691
diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs
index afec9fe0aa2..5ce59cc1e36 100644
--- a/crates/vim/src/motion.rs
+++ b/crates/vim/src/motion.rs
@@ -1273,16 +1273,19 @@ fn wrapping_right(map: &DisplaySnapshot, mut point: DisplayPoint, times: usize)
point
}
-fn wrapping_right_single(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
- let max_column = map.line_len(point.row()).saturating_sub(1);
- if point.column() < max_column {
- *point.column_mut() += 1;
- point = map.clip_point(point, Bias::Right);
- } else if point.row() < map.max_point().row() {
- *point.row_mut() += 1;
- *point.column_mut() = 0;
+fn wrapping_right_single(map: &DisplaySnapshot, point: DisplayPoint) -> DisplayPoint {
+ let mut next_point = point;
+ *next_point.column_mut() += 1;
+ next_point = map.clip_point(next_point, Bias::Right);
+ if next_point == point {
+ if next_point.row() == map.max_point().row() {
+ next_point
+ } else {
+ DisplayPoint::new(next_point.row().next_row(), 0)
+ }
+ } else {
+ next_point
}
- point
}
pub(crate) fn start_of_relative_buffer_row(
@@ -3563,4 +3566,32 @@ mod test {
cx.simulate_shared_keystrokes("3 space").await;
cx.shared_state().await.assert_eq("πππˇππ");
}
+
+ #[gpui::test]
+ async fn test_space_non_ascii_eol(cx: &mut gpui::TestAppContext) {
+ let mut cx = NeovimBackedTestContext::new(cx).await;
+
+ cx.set_shared_state(indoc! {"
+ ππππˇπ
+ πanotherline"})
+ .await;
+ cx.simulate_shared_keystrokes("4 space").await;
+ cx.shared_state().await.assert_eq(indoc! {"
+ πππππ
+ πanˇotherline"});
+ }
+
+ #[gpui::test]
+ async fn test_backspace_non_ascii_bol(cx: &mut gpui::TestAppContext) {
+ let mut cx = NeovimBackedTestContext::new(cx).await;
+
+ cx.set_shared_state(indoc! {"
+ ππππ
+ πanˇotherline"})
+ .await;
+ cx.simulate_shared_keystrokes("4 backspace").await;
+ cx.shared_state().await.assert_eq(indoc! {"
+ πππˇπ
+ πanotherline"});
+ }
}
diff --git a/crates/vim/test_data/test_backspace_non_ascii_bol.json b/crates/vim/test_data/test_backspace_non_ascii_bol.json
new file mode 100644
index 00000000000..88536bc50d7
--- /dev/null
+++ b/crates/vim/test_data/test_backspace_non_ascii_bol.json
@@ -0,0 +1,4 @@
+{"Put":{"state":"ππππ\nπanˇotherline"}}
+{"Key":"4"}
+{"Key":"backspace"}
+{"Get":{"state":"πππˇπ\nπanotherline","mode":"Normal"}}
diff --git a/crates/vim/test_data/test_space_non_ascii_eol.json b/crates/vim/test_data/test_space_non_ascii_eol.json
new file mode 100644
index 00000000000..6c1bb73fa56
--- /dev/null
+++ b/crates/vim/test_data/test_space_non_ascii_eol.json
@@ -0,0 +1,4 @@
+{"Put":{"state":"ππππˇπ\nπanotherline"}}
+{"Key":"4"}
+{"Key":"space"}
+{"Get":{"state":"πππππ\nπanˇotherline","mode":"Normal"}}
diff --git a/crates/vim/test_data/test_space_only_ascii_eol.json b/crates/vim/test_data/test_space_only_ascii_eol.json
new file mode 100644
index 00000000000..43a3af79453
--- /dev/null
+++ b/crates/vim/test_data/test_space_only_ascii_eol.json
@@ -0,0 +1,4 @@
+{"Put":{"state":"aaaaˇaa\nanotherline"}}
+{"Key":"4"}
+{"Key":"space"}
+{"Get":{"state":"aaaaaa\nanˇotherline","mode":"Normal"}}