History

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

Hans committed 2 years ago

Commit d0446851 parent 0496d0d2 files · +34 −3Browse files

Unified · Split

2 files
  1. crates/vim/src/object.rs +24 −3
  2. crates/vim/test_data/test_singleline_surrounding_character_objects.json +10 −0
crates/vim/src/object.rs+24−3
@@ -838,13 +838,16 @@ fn surrounding_markers( · 837 unmodified lines
838 }838 }
839 839
840 if opening.is_none() {840 if opening.is_none() {
841 for ((ch, range), (before_ch, _)) in movement::chars_before(map, point).tuple_windows() {841 let mut chars_before = movement::chars_before(map, point).peekable();
842 while let Some((ch, range)) = chars_before.next() {
842 if ch == '\n' && !search_across_lines {843 if ch == '\n' && !search_across_lines {
843 break;844 break;
844 }845 }
845 846
846 if before_ch == '\\' {847 if let Some((before_ch, _)) = chars_before.peek() {
847 continue;848 if *before_ch == '\\' {
849 continue;
850 }
848 }851 }
849 852
850 if ch == open_marker {853 if ch == open_marker {
@@ -1209,6 +1212,24 @@ mod test { · 358 unmodified lines
1209 let mut cx = NeovimBackedTestContext::new(cx).await;1212 let mut cx = NeovimBackedTestContext::new(cx).await;
1210 cx.set_shared_wrap(12).await;1213 cx.set_shared_wrap(12).await;
1211 1214
1215 cx.set_shared_state(indoc! {
1216 "\"ˇhello world\"!"
1217 })
1218 .await;
1219 cx.simulate_shared_keystrokes("v i \"").await;
1220 cx.shared_state().await.assert_eq(indoc! {
1221 "\"«hello worldˇ»\"!"
1222 });
1223
1224 cx.set_shared_state(indoc! {
1225 "\"hˇello world\"!"
1226 })
1227 .await;
1228 cx.simulate_shared_keystrokes("v i \"").await;
1229 cx.shared_state().await.assert_eq(indoc! {
1230 "\"«hello worldˇ»\"!"
1231 });
1232
1212 cx.set_shared_state(indoc! {1233 cx.set_shared_state(indoc! {
1213 "helˇlo \"world\"!"1234 "helˇlo \"world\"!"
1214 })1235 })
crates/vim/test_data/test_singleline_surrounding_character_objects.json+10−0
@@ -1,5 +1,15 @@
1{"SetOption":{"value":"wrap"}}1{"SetOption":{"value":"wrap"}}
2{"SetOption":{"value":"columns=12"}}2{"SetOption":{"value":"columns=12"}}
3{"Put":{"state":"\"ˇhello world\"!"}}
4{"Key":"v"}
5{"Key":"i"}
6{"Key":"\""}
7{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}}
8{"Put":{"state":"\"hˇello world\"!"}}
9{"Key":"v"}
10{"Key":"i"}
11{"Key":"\""}
12{"Get":{"state":"\"«hello worldˇ»\"!","mode":"Visual"}}
3{"Put":{"state":"helˇlo \"world\"!"}}13{"Put":{"state":"helˇlo \"world\"!"}}
4{"Key":"v"}14{"Key":"v"}
5{"Key":"i"}15{"Key":"i"}