Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
vim: Make end of line infallible (#48867)
Dinoad7b1f52b46e
diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rsindex 8d14e5a3e2c..b33d85bc5a5 100644--- a/crates/vim/src/motion.rs+++ b/crates/vim/src/motion.rs@@ -899,10 +899,9 @@ impl Motion {pub fn infallible(&self) -> bool {use Motion::*;match self {- StartOfDocument | EndOfDocument | CurrentLine => true,+ StartOfDocument | EndOfDocument | CurrentLine | EndOfLine { .. } => true,Down { .. }| Up { .. }- | EndOfLine { .. }| MiddleOfLine { .. }| Matching { .. }| UnmatchedForward { .. }@@ -3901,6 +3900,29 @@ mod test {jumps over thelazy dog"});++ // Test that, when the cursor is moved to the end of the line using `l`,+ // if `$` is used, the cursor stays at the end of the line when moving+ // to a longer line, ensuring that the selection goal was correctly+ // updated.+ cx.set_shared_state(indoc! {"+ The quick brown fox+ jumps over the+ lazy dˇog+ "})+ .await;+ cx.simulate_shared_keystrokes("l").await;+ cx.shared_state().await.assert_eq(indoc! {"+ The quick brown fox+ jumps over the+ lazy doˇg+ "});+ cx.simulate_shared_keystrokes("$ k").await;+ cx.shared_state().await.assert_eq(indoc! {"+ The quick brown fox+ jumps over thˇe+ lazy dog+ "});}#[gpui::test]diff --git a/crates/vim/test_data/test_end_of_line_with_vertical_motion.json b/crates/vim/test_data/test_end_of_line_with_vertical_motion.jsonindex 16487a5d4c2..35d16b2843f 100644--- a/crates/vim/test_data/test_end_of_line_with_vertical_motion.json+++ b/crates/vim/test_data/test_end_of_line_with_vertical_motion.json@@ -14,3 +14,9 @@{"Get":{"state":"The quick brown fox\njumps ˇover the\nlazy dog\n","mode":"Normal"}}{"Key":"k"}{"Get":{"state":"The quˇick brown fox\njumps over the\nlazy dog\n","mode":"Normal"}}+{"Put":{"state":"The quick brown fox\njumps over the\nlazy dˇog\n"}}+{"Key":"l"}+{"Get":{"state":"The quick brown fox\njumps over the\nlazy doˇg\n","mode":"Normal"}}+{"Key":"$"}+{"Key":"k"}+{"Get":{"state":"The quick brown fox\njumps over thˇe\nlazy dog\n","mode":"Normal"}}