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
838838 }
839839
840840 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() {
842843 if ch == '\n' && !search_across_lines {
843844 break;
844845 }
845846
846− if before_ch == '\\' {
847− continue;
847+ if let Some((before_ch, _)) = chars_before.peek() {
848+ if *before_ch == '\\' {
849+ continue;
850+ }
848851 }
849852
850853 if ch == open_marker {
@@ -1209,6 +1212,24 @@ mod test { · 358 unmodified lines
12091212 let mut cx = NeovimBackedTestContext::new(cx).await;
12101213 cx.set_shared_wrap(12).await;
12111214
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+
12121233 cx.set_shared_state(indoc! {
12131234 "helˇlo \"world\"!"
12141235 })
crates/vim/test_data/test_singleline_surrounding_character_objects.json+10−0
@@ -1,5 +1,15 @@
11 {"SetOption":{"value":"wrap"}}
22 {"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"}}
313 {"Put":{"state":"helˇlo \"world\"!"}}
414 {"Key":"v"}
515 {"Key":"i"}