Compare commits

...

3 Commits

Author SHA1 Message Date
Conrad Irwin
69dc65d7bc Don't use +1 2025-04-29 13:18:56 -06:00
dinocosta
d24747a8b0 refactor(vim): move d} fix to range method
Update the fix for the `d}` delete motion from
`Motion::move_point` to `Motion::range` in order to avoid
breaking other commands that rely on the `}` motion.

This also fixes the tests that were failing and introduces
a new test to ensure the `}` delete motion works as expected.
2025-04-29 11:10:03 -07:00
dinocosta
c559b5bb59 fix(delete): fix end of paragraph deletion for buffers with no newlines
This commit attempts to fix an issue where using `d}` in vim mode would
not delete all characters in case there's no newlines at the end of the
buffer.

When calculating the end point for this motion, if there's no newline at
the end of the buffer, Zed was calculating it to be the last character
in the last line. However, if there's a newline at the end of the
buffer, it correctly calculates the end point to be the character at the
right of the last character.

Here's an example, for the following buffer contents:

```
Hello!
Hello!
```

If the `d}` command is run at (0, 0), the end point will be set to (1,
5). However, fi the same command is run for this buffer instead:

```
Hello!
Hello!

```

The end point will be set to (1, 6), there's a 1 unit difference in the
column, which leads to all characters actually being deleted.
2025-04-26 15:10:44 -07:00
3 changed files with 41 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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"}}