vim: Increment search right (#10866)

Hi there, nice editor!
Here's my attempt at fixing #10865.

Thanks

Release Notes:

-vim: Fix ctrl+a when cursor is on a decimal point
([#10865](https://github.com/zed-industries/zed/issues/10865)).

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Hendrik Sollich 2024-04-26 03:47:52 +02:00 committed by GitHub
parent d9eb3c4b35
commit 604857ed2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 61 additions and 6 deletions

View File

@ -117,13 +117,16 @@ fn find_number(
) -> Option<(Range<Point>, String, u32)> {
let mut offset = start.to_offset(snapshot);
// go backwards to the start of any number the selection is within
for ch in snapshot.reversed_chars_at(offset) {
if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {
offset -= ch.len_utf8();
continue;
let ch0 = snapshot.chars_at(offset).next();
if ch0.as_ref().is_some_and(char::is_ascii_digit) || matches!(ch0, Some('-' | 'b' | 'x')) {
// go backwards to the start of any number the selection is within
for ch in snapshot.reversed_chars_at(offset) {
if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {
offset -= ch.len_utf8();
continue;
}
break;
}
break;
}
let mut begin = None;
@ -217,6 +220,48 @@ mod test {
.await;
}
#[gpui::test]
async fn test_increment_with_dot(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {"
1ˇ.2
"})
.await;
cx.simulate_shared_keystrokes(["ctrl-a"]).await;
cx.assert_shared_state(indoc! {"
1.ˇ3
"})
.await;
cx.simulate_shared_keystrokes(["ctrl-x"]).await;
cx.assert_shared_state(indoc! {"
1.ˇ2
"})
.await;
}
#[gpui::test]
async fn test_increment_with_two_dots(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {"
111.ˇ.2
"})
.await;
cx.simulate_shared_keystrokes(["ctrl-a"]).await;
cx.assert_shared_state(indoc! {"
111..ˇ3
"})
.await;
cx.simulate_shared_keystrokes(["ctrl-x"]).await;
cx.assert_shared_state(indoc! {"
111..ˇ2
"})
.await;
}
#[gpui::test]
async fn test_increment_radix(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View File

@ -0,0 +1,5 @@
{"Put":{"state":"1ˇ.2\n"}}
{"Key":"ctrl-a"}
{"Get":{"state":"1.ˇ3\n","mode":"Normal"}}
{"Key":"ctrl-x"}
{"Get":{"state":"1.ˇ2\n","mode":"Normal"}}

View File

@ -0,0 +1,5 @@
{"Put":{"state":"111.ˇ.2\n"}}
{"Key":"ctrl-a"}
{"Get":{"state":"111..ˇ3\n","mode":"Normal"}}
{"Key":"ctrl-x"}
{"Get":{"state":"111..ˇ2\n","mode":"Normal"}}