vim: Adjust surrounding_markers method (#14752)

At present, when calculating some ranges, we take the `tuple_windows` to
iterate forward, which will cause some problems when the cursor is being
front, because `tuple_windows` iteration cannot iterate to the very
beginning, so there will be some cases that cannot be calculated, adjust
this method, and now it can calculate more perfectly, and the execution
speed is about the same

Release Notes:

- N/A
This commit is contained in:
Hans 2024-07-19 01:53:51 +08:00 committed by GitHub
parent 0496d0db9a
commit d044685706
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View File

@ -838,14 +838,17 @@ fn surrounding_markers(
}
if opening.is_none() {
for ((ch, range), (before_ch, _)) in movement::chars_before(map, point).tuple_windows() {
let mut chars_before = movement::chars_before(map, point).peekable();
while let Some((ch, range)) = chars_before.next() {
if ch == '\n' && !search_across_lines {
break;
}
if before_ch == '\\' {
if let Some((before_ch, _)) = chars_before.peek() {
if *before_ch == '\\' {
continue;
}
}
if ch == open_marker {
if matched_closes == 0 {
@ -1209,6 +1212,24 @@ mod test {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_wrap(12).await;
cx.set_shared_state(indoc! {
"\"ˇhello world\"!"
})
.await;
cx.simulate_shared_keystrokes("v i \"").await;
cx.shared_state().await.assert_eq(indoc! {
"\"«hello worldˇ»\"!"
});
cx.set_shared_state(indoc! {
"\"hˇello world\"!"
})
.await;
cx.simulate_shared_keystrokes("v i \"").await;
cx.shared_state().await.assert_eq(indoc! {
"\"«hello worldˇ»\"!"
});
cx.set_shared_state(indoc! {
"helˇlo \"world\"!"
})

View File

@ -1,5 +1,15 @@
{"SetOption":{"value":"wrap"}}
{"SetOption":{"value":"columns=12"}}
{"Put":{"state":"\"ˇhello world\"!"}}
{"Key":"v"}
{"Key":"i"}
{"Key":"\""}
{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}}
{"Put":{"state":"\"hˇello world\"!"}}
{"Key":"v"}
{"Key":"i"}
{"Key":"\""}
{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}}
{"Put":{"state":"helˇlo \"world\"!"}}
{"Key":"v"}
{"Key":"i"}