mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-19 02:17:35 +03:00
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:
parent
d9eb3c4b35
commit
604857ed2e
@ -117,13 +117,16 @@ fn find_number(
|
|||||||
) -> Option<(Range<Point>, String, u32)> {
|
) -> Option<(Range<Point>, String, u32)> {
|
||||||
let mut offset = start.to_offset(snapshot);
|
let mut offset = start.to_offset(snapshot);
|
||||||
|
|
||||||
// go backwards to the start of any number the selection is within
|
let ch0 = snapshot.chars_at(offset).next();
|
||||||
for ch in snapshot.reversed_chars_at(offset) {
|
if ch0.as_ref().is_some_and(char::is_ascii_digit) || matches!(ch0, Some('-' | 'b' | 'x')) {
|
||||||
if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {
|
// go backwards to the start of any number the selection is within
|
||||||
offset -= ch.len_utf8();
|
for ch in snapshot.reversed_chars_at(offset) {
|
||||||
continue;
|
if ch.is_ascii_digit() || ch == '-' || ch == 'b' || ch == 'x' {
|
||||||
|
offset -= ch.len_utf8();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut begin = None;
|
let mut begin = None;
|
||||||
@ -217,6 +220,48 @@ mod test {
|
|||||||
.await;
|
.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]
|
#[gpui::test]
|
||||||
async fn test_increment_radix(cx: &mut gpui::TestAppContext) {
|
async fn test_increment_radix(cx: &mut gpui::TestAppContext) {
|
||||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
5
crates/vim/test_data/test_increment_with_dot.json
Normal file
5
crates/vim/test_data/test_increment_with_dot.json
Normal 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"}}
|
5
crates/vim/test_data/test_increment_with_two_dots.json
Normal file
5
crates/vim/test_data/test_increment_with_two_dots.json
Normal 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"}}
|
Loading…
Reference in New Issue
Block a user