From 45ae0dcc2dfb93876cc6f957aa5a918b0004b40d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 14 Jun 2024 13:18:28 -0600 Subject: [PATCH] Fix dw at the end of a soft wrapped line (#13065) Co-Authored-By: Richard Release Notes: - vim: Fixed behavior of `dw` at the end of a soft wrapped line Co-authored-by: Richard --- crates/vim/src/motion.rs | 18 ++++++++++-------- crates/vim/src/test.rs | 14 ++++++++++++++ crates/vim/test_data/test_dw_eol.json | 6 ++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 crates/vim/test_data/test_dw_eol.json diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 2b430a0e48..c99901e2fa 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -873,18 +873,20 @@ impl Motion { // becomes inclusive. Example: "}" moves to the first line after a paragraph, // but "d}" will not include that line. let mut inclusive = self.inclusive(); + let start_point = selection.start.to_point(&map); + let mut end_point = selection.end.to_point(&map); + + // DisplayPoint + if !inclusive && self != &Motion::Backspace - && selection.end.row() > selection.start.row() - && selection.end.column() == 0 + && end_point.row > start_point.row + && end_point.column == 0 { inclusive = true; - *selection.end.row_mut() -= 1; - *selection.end.column_mut() = 0; - selection.end = map.clip_point( - map.next_line_boundary(selection.end.to_point(map)).1, - Bias::Left, - ); + end_point.row -= 1; + end_point.column = 0; + selection.end = map.clip_point(map.next_line_boundary(end_point).1, Bias::Left); } if inclusive && selection.end.column() < map.line_len(selection.end.row()) { diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 5340310270..d3134fce90 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -1197,3 +1197,17 @@ async fn test_caret_mark(cx: &mut TestAppContext) { " }); } + +#[cfg(target_os = "macos")] +#[gpui::test] +async fn test_dw_eol(cx: &mut gpui::TestAppContext) { + let mut cx = NeovimBackedTestContext::new(cx).await; + + cx.set_shared_wrap(12).await; + cx.set_shared_state("twelve ˇchar twelve char\ntwelve char") + .await; + cx.simulate_shared_keystrokes("d w").await; + cx.shared_state() + .await + .assert_eq("twelve ˇtwelve char\ntwelve char"); +} diff --git a/crates/vim/test_data/test_dw_eol.json b/crates/vim/test_data/test_dw_eol.json new file mode 100644 index 0000000000..93ec9b1066 --- /dev/null +++ b/crates/vim/test_data/test_dw_eol.json @@ -0,0 +1,6 @@ +{"SetOption":{"value":"wrap"}} +{"SetOption":{"value":"columns=12"}} +{"Put":{"state":"twelve ˇchar twelve char\ntwelve char"}} +{"Key":"d"} +{"Key":"w"} +{"Get":{"state":"twelve ˇtwelve char\ntwelve char","mode":"Normal"}}