diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 8d14e5a3e2c9b0e9be207942275b8ea447f43c70..b33d85bc5a5398b912ea999865729c362dced995 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 the lazy 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.json index 16487a5d4c25a32d096ae274ec023b7d9ebf8c55..35d16b2843f5c829e3272a72b2edd8e0574ed8c1 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"}}