normal.rs

  1mod case;
  2mod change;
  3mod delete;
  4mod increment;
  5mod paste;
  6pub(crate) mod repeat;
  7mod scroll;
  8pub(crate) mod search;
  9pub mod substitute;
 10mod yank;
 11
 12use std::sync::Arc;
 13
 14use crate::{
 15    motion::{self, first_non_whitespace, next_line_end, right, Motion},
 16    object::Object,
 17    state::{Mode, Operator},
 18    Vim,
 19};
 20use collections::HashSet;
 21use editor::scroll::autoscroll::Autoscroll;
 22use editor::{Bias, DisplayPoint};
 23use gpui::{actions, ViewContext, WindowContext};
 24use language::SelectionGoal;
 25use log::error;
 26use workspace::Workspace;
 27
 28use self::{
 29    case::change_case,
 30    change::{change_motion, change_object},
 31    delete::{delete_motion, delete_object},
 32    yank::{yank_motion, yank_object},
 33};
 34
 35actions!(
 36    vim,
 37    [
 38        InsertAfter,
 39        InsertBefore,
 40        InsertFirstNonWhitespace,
 41        InsertEndOfLine,
 42        InsertLineAbove,
 43        InsertLineBelow,
 44        DeleteLeft,
 45        DeleteRight,
 46        ChangeToEndOfLine,
 47        DeleteToEndOfLine,
 48        Yank,
 49        YankLine,
 50        ChangeCase,
 51        JoinLines,
 52    ]
 53);
 54
 55pub(crate) fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
 56    dbg!("registering");
 57    workspace.register_action(insert_after);
 58    workspace.register_action(insert_before);
 59    workspace.register_action(insert_first_non_whitespace);
 60    workspace.register_action(insert_end_of_line);
 61    workspace.register_action(insert_line_above);
 62    workspace.register_action(insert_line_below);
 63    workspace.register_action(change_case);
 64    workspace.register_action(yank_line);
 65
 66    workspace.register_action(|_: &mut Workspace, _: &DeleteLeft, cx| {
 67        Vim::update(cx, |vim, cx| {
 68            vim.record_current_action(cx);
 69            let times = vim.take_count(cx);
 70            delete_motion(vim, Motion::Left, times, cx);
 71        })
 72    });
 73    workspace.register_action(|_: &mut Workspace, _: &DeleteRight, cx| {
 74        Vim::update(cx, |vim, cx| {
 75            vim.record_current_action(cx);
 76            let times = vim.take_count(cx);
 77            delete_motion(vim, Motion::Right, times, cx);
 78        })
 79    });
 80    workspace.register_action(|_: &mut Workspace, _: &ChangeToEndOfLine, cx| {
 81        Vim::update(cx, |vim, cx| {
 82            vim.start_recording(cx);
 83            let times = vim.take_count(cx);
 84            change_motion(
 85                vim,
 86                Motion::EndOfLine {
 87                    display_lines: false,
 88                },
 89                times,
 90                cx,
 91            );
 92        })
 93    });
 94    workspace.register_action(|_: &mut Workspace, _: &DeleteToEndOfLine, cx| {
 95        Vim::update(cx, |vim, cx| {
 96            vim.record_current_action(cx);
 97            let times = vim.take_count(cx);
 98            delete_motion(
 99                vim,
100                Motion::EndOfLine {
101                    display_lines: false,
102                },
103                times,
104                cx,
105            );
106        })
107    });
108    workspace.register_action(|_: &mut Workspace, _: &JoinLines, cx| {
109        Vim::update(cx, |vim, cx| {
110            vim.record_current_action(cx);
111            let mut times = vim.take_count(cx).unwrap_or(1);
112            if vim.state().mode.is_visual() {
113                times = 1;
114            } else if times > 1 {
115                // 2J joins two lines together (same as J or 1J)
116                times -= 1;
117            }
118
119            vim.update_active_editor(cx, |editor, cx| {
120                editor.transact(cx, |editor, cx| {
121                    for _ in 0..times {
122                        editor.join_lines(&Default::default(), cx)
123                    }
124                })
125            })
126        });
127    });
128
129    paste::register(workspace, cx);
130    repeat::register(workspace, cx);
131    scroll::register(workspace, cx);
132    search::register(workspace, cx);
133    substitute::register(workspace, cx);
134    increment::register(workspace, cx);
135}
136
137pub fn normal_motion(
138    motion: Motion,
139    operator: Option<Operator>,
140    times: Option<usize>,
141    cx: &mut WindowContext,
142) {
143    Vim::update(cx, |vim, cx| {
144        match operator {
145            None => move_cursor(vim, motion, times, cx),
146            Some(Operator::Change) => change_motion(vim, motion, times, cx),
147            Some(Operator::Delete) => delete_motion(vim, motion, times, cx),
148            Some(Operator::Yank) => yank_motion(vim, motion, times, cx),
149            Some(operator) => {
150                // Can't do anything for text objects, Ignoring
151                error!("Unexpected normal mode motion operator: {:?}", operator)
152            }
153        }
154    });
155}
156
157pub fn normal_object(object: Object, cx: &mut WindowContext) {
158    Vim::update(cx, |vim, cx| {
159        match vim.maybe_pop_operator() {
160            Some(Operator::Object { around }) => match vim.maybe_pop_operator() {
161                Some(Operator::Change) => change_object(vim, object, around, cx),
162                Some(Operator::Delete) => delete_object(vim, object, around, cx),
163                Some(Operator::Yank) => yank_object(vim, object, around, cx),
164                _ => {
165                    // Can't do anything for namespace operators. Ignoring
166                }
167            },
168            _ => {
169                // Can't do anything with change/delete/yank and text objects. Ignoring
170            }
171        }
172        vim.clear_operator(cx);
173    })
174}
175
176pub(crate) fn move_cursor(
177    vim: &mut Vim,
178    motion: Motion,
179    times: Option<usize>,
180    cx: &mut WindowContext,
181) {
182    vim.update_active_editor(cx, |editor, cx| {
183        let text_layout_details = editor.text_layout_details(cx);
184        editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
185            s.move_cursors_with(|map, cursor, goal| {
186                motion
187                    .move_point(map, cursor, goal, times, &text_layout_details)
188                    .unwrap_or((cursor, goal))
189            })
190        })
191    });
192}
193
194fn insert_after(_: &mut Workspace, _: &InsertAfter, cx: &mut ViewContext<Workspace>) {
195    Vim::update(cx, |vim, cx| {
196        vim.start_recording(cx);
197        vim.switch_mode(Mode::Insert, false, cx);
198        vim.update_active_editor(cx, |editor, cx| {
199            editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
200                s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None));
201            });
202        });
203    });
204}
205
206fn insert_before(_: &mut Workspace, _: &InsertBefore, cx: &mut ViewContext<Workspace>) {
207    dbg!("insert before!");
208    Vim::update(cx, |vim, cx| {
209        vim.start_recording(cx);
210        vim.switch_mode(Mode::Insert, false, cx);
211    });
212}
213
214fn insert_first_non_whitespace(
215    _: &mut Workspace,
216    _: &InsertFirstNonWhitespace,
217    cx: &mut ViewContext<Workspace>,
218) {
219    Vim::update(cx, |vim, cx| {
220        vim.start_recording(cx);
221        vim.switch_mode(Mode::Insert, false, cx);
222        vim.update_active_editor(cx, |editor, cx| {
223            editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
224                s.move_cursors_with(|map, cursor, _| {
225                    (
226                        first_non_whitespace(map, false, cursor),
227                        SelectionGoal::None,
228                    )
229                });
230            });
231        });
232    });
233}
234
235fn insert_end_of_line(_: &mut Workspace, _: &InsertEndOfLine, cx: &mut ViewContext<Workspace>) {
236    Vim::update(cx, |vim, cx| {
237        vim.start_recording(cx);
238        vim.switch_mode(Mode::Insert, false, cx);
239        vim.update_active_editor(cx, |editor, cx| {
240            editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
241                s.move_cursors_with(|map, cursor, _| {
242                    (next_line_end(map, cursor, 1), SelectionGoal::None)
243                });
244            });
245        });
246    });
247}
248
249fn insert_line_above(_: &mut Workspace, _: &InsertLineAbove, cx: &mut ViewContext<Workspace>) {
250    Vim::update(cx, |vim, cx| {
251        vim.start_recording(cx);
252        vim.switch_mode(Mode::Insert, false, cx);
253        vim.update_active_editor(cx, |editor, cx| {
254            editor.transact(cx, |editor, cx| {
255                let (map, old_selections) = editor.selections.all_display(cx);
256                let selection_start_rows: HashSet<u32> = old_selections
257                    .into_iter()
258                    .map(|selection| selection.start.row())
259                    .collect();
260                let edits = selection_start_rows.into_iter().map(|row| {
261                    let (indent, _) = map.line_indent(row);
262                    let start_of_line =
263                        motion::start_of_line(&map, false, DisplayPoint::new(row, 0))
264                            .to_point(&map);
265                    let mut new_text = " ".repeat(indent as usize);
266                    new_text.push('\n');
267                    (start_of_line..start_of_line, new_text)
268                });
269                editor.edit_with_autoindent(edits, cx);
270                editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
271                    s.move_cursors_with(|map, cursor, _| {
272                        let previous_line = motion::start_of_relative_buffer_row(map, cursor, -1);
273                        let insert_point = motion::end_of_line(map, false, previous_line);
274                        (insert_point, SelectionGoal::None)
275                    });
276                });
277            });
278        });
279    });
280}
281
282fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContext<Workspace>) {
283    Vim::update(cx, |vim, cx| {
284        vim.start_recording(cx);
285        vim.switch_mode(Mode::Insert, false, cx);
286        vim.update_active_editor(cx, |editor, cx| {
287            let text_layout_details = editor.text_layout_details(cx);
288            editor.transact(cx, |editor, cx| {
289                let (map, old_selections) = editor.selections.all_display(cx);
290
291                let selection_end_rows: HashSet<u32> = old_selections
292                    .into_iter()
293                    .map(|selection| selection.end.row())
294                    .collect();
295                let edits = selection_end_rows.into_iter().map(|row| {
296                    let (indent, _) = map.line_indent(row);
297                    let end_of_line =
298                        motion::end_of_line(&map, false, DisplayPoint::new(row, 0)).to_point(&map);
299
300                    let mut new_text = "\n".to_string();
301                    new_text.push_str(&" ".repeat(indent as usize));
302                    (end_of_line..end_of_line, new_text)
303                });
304                editor.change_selections(Some(Autoscroll::fit()), cx, |s| {
305                    s.maybe_move_cursors_with(|map, cursor, goal| {
306                        Motion::CurrentLine.move_point(
307                            map,
308                            cursor,
309                            goal,
310                            None,
311                            &text_layout_details,
312                        )
313                    });
314                });
315                editor.edit_with_autoindent(edits, cx);
316            });
317        });
318    });
319}
320
321fn yank_line(_: &mut Workspace, _: &YankLine, cx: &mut ViewContext<Workspace>) {
322    Vim::update(cx, |vim, cx| {
323        let count = vim.take_count(cx);
324        yank_motion(vim, motion::Motion::CurrentLine, count, cx)
325    })
326}
327
328pub(crate) fn normal_replace(text: Arc<str>, cx: &mut WindowContext) {
329    Vim::update(cx, |vim, cx| {
330        vim.stop_recording();
331        vim.update_active_editor(cx, |editor, cx| {
332            editor.transact(cx, |editor, cx| {
333                editor.set_clip_at_line_ends(false, cx);
334                let (map, display_selections) = editor.selections.all_display(cx);
335                // Selections are biased right at the start. So we need to store
336                // anchors that are biased left so that we can restore the selections
337                // after the change
338                let stable_anchors = editor
339                    .selections
340                    .disjoint_anchors()
341                    .into_iter()
342                    .map(|selection| {
343                        let start = selection.start.bias_left(&map.buffer_snapshot);
344                        start..start
345                    })
346                    .collect::<Vec<_>>();
347
348                let edits = display_selections
349                    .into_iter()
350                    .map(|selection| {
351                        let mut range = selection.range();
352                        *range.end.column_mut() += 1;
353                        range.end = map.clip_point(range.end, Bias::Right);
354
355                        (
356                            range.start.to_offset(&map, Bias::Left)
357                                ..range.end.to_offset(&map, Bias::Left),
358                            text.clone(),
359                        )
360                    })
361                    .collect::<Vec<_>>();
362
363                editor.buffer().update(cx, |buffer, cx| {
364                    buffer.edit(edits, None, cx);
365                });
366                editor.set_clip_at_line_ends(true, cx);
367                editor.change_selections(None, cx, |s| {
368                    s.select_anchor_ranges(stable_anchors);
369                });
370            });
371        });
372        vim.pop_operator(cx)
373    });
374}
375
376// #[cfg(test)]
377// mod test {
378//     use gpui::TestAppContext;
379//     use indoc::indoc;
380
381//     use crate::{
382//         state::Mode::{self},
383//         test::NeovimBackedTestContext,
384//     };
385
386//     #[gpui::test]
387//     async fn test_h(cx: &mut gpui::TestAppContext) {
388//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["h"]);
389//         cx.assert_all(indoc! {"
390//             ˇThe qˇuick
391//             ˇbrown"
392//         })
393//         .await;
394//     }
395
396//     #[gpui::test]
397//     async fn test_backspace(cx: &mut gpui::TestAppContext) {
398//         let mut cx = NeovimBackedTestContext::new(cx)
399//             .await
400//             .binding(["backspace"]);
401//         cx.assert_all(indoc! {"
402//             ˇThe qˇuick
403//             ˇbrown"
404//         })
405//         .await;
406//     }
407
408//     #[gpui::test]
409//     async fn test_j(cx: &mut gpui::TestAppContext) {
410//         let mut cx = NeovimBackedTestContext::new(cx).await;
411
412//         cx.set_shared_state(indoc! {"
413//                     aaˇaa
414//                     😃😃"
415//         })
416//         .await;
417//         cx.simulate_shared_keystrokes(["j"]).await;
418//         cx.assert_shared_state(indoc! {"
419//                     aaaa
420//                     😃ˇ😃"
421//         })
422//         .await;
423
424//         for marked_position in cx.each_marked_position(indoc! {"
425//                     ˇThe qˇuick broˇwn
426//                     ˇfox jumps"
427//         }) {
428//             cx.assert_neovim_compatible(&marked_position, ["j"]).await;
429//         }
430//     }
431
432//     #[gpui::test]
433//     async fn test_enter(cx: &mut gpui::TestAppContext) {
434//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["enter"]);
435//         cx.assert_all(indoc! {"
436//             ˇThe qˇuick broˇwn
437//             ˇfox jumps"
438//         })
439//         .await;
440//     }
441
442//     #[gpui::test]
443//     async fn test_k(cx: &mut gpui::TestAppContext) {
444//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["k"]);
445//         cx.assert_all(indoc! {"
446//             ˇThe qˇuick
447//             ˇbrown fˇox jumˇps"
448//         })
449//         .await;
450//     }
451
452//     #[gpui::test]
453//     async fn test_l(cx: &mut gpui::TestAppContext) {
454//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["l"]);
455//         cx.assert_all(indoc! {"
456//             ˇThe qˇuicˇk
457//             ˇbrowˇn"})
458//             .await;
459//     }
460
461//     #[gpui::test]
462//     async fn test_jump_to_line_boundaries(cx: &mut gpui::TestAppContext) {
463//         let mut cx = NeovimBackedTestContext::new(cx).await;
464//         cx.assert_binding_matches_all(
465//             ["$"],
466//             indoc! {"
467//             ˇThe qˇuicˇk
468//             ˇbrowˇn"},
469//         )
470//         .await;
471//         cx.assert_binding_matches_all(
472//             ["0"],
473//             indoc! {"
474//                 ˇThe qˇuicˇk
475//                 ˇbrowˇn"},
476//         )
477//         .await;
478//     }
479
480//     #[gpui::test]
481//     async fn test_jump_to_end(cx: &mut gpui::TestAppContext) {
482//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["shift-g"]);
483
484//         cx.assert_all(indoc! {"
485//                 The ˇquick
486
487//                 brown fox jumps
488//                 overˇ the lazy doˇg"})
489//             .await;
490//         cx.assert(indoc! {"
491//             The quiˇck
492
493//             brown"})
494//             .await;
495//         cx.assert(indoc! {"
496//             The quiˇck
497
498//             "})
499//             .await;
500//     }
501
502//     #[gpui::test]
503//     async fn test_w(cx: &mut gpui::TestAppContext) {
504//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["w"]);
505//         cx.assert_all(indoc! {"
506//             The ˇquickˇ-ˇbrown
507//             ˇ
508//             ˇ
509//             ˇfox_jumps ˇover
510//             ˇthˇe"})
511//             .await;
512//         let mut cx = cx.binding(["shift-w"]);
513//         cx.assert_all(indoc! {"
514//             The ˇquickˇ-ˇbrown
515//             ˇ
516//             ˇ
517//             ˇfox_jumps ˇover
518//             ˇthˇe"})
519//             .await;
520//     }
521
522//     #[gpui::test]
523//     async fn test_end_of_word(cx: &mut gpui::TestAppContext) {
524//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["e"]);
525//         cx.assert_all(indoc! {"
526//             Thˇe quicˇkˇ-browˇn
527
528//             fox_jumpˇs oveˇr
529//             thˇe"})
530//             .await;
531//         let mut cx = cx.binding(["shift-e"]);
532//         cx.assert_all(indoc! {"
533//             Thˇe quicˇkˇ-browˇn
534
535//             fox_jumpˇs oveˇr
536//             thˇe"})
537//             .await;
538//     }
539
540//     #[gpui::test]
541//     async fn test_b(cx: &mut gpui::TestAppContext) {
542//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["b"]);
543//         cx.assert_all(indoc! {"
544//             ˇThe ˇquickˇ-ˇbrown
545//             ˇ
546//             ˇ
547//             ˇfox_jumps ˇover
548//             ˇthe"})
549//             .await;
550//         let mut cx = cx.binding(["shift-b"]);
551//         cx.assert_all(indoc! {"
552//             ˇThe ˇquickˇ-ˇbrown
553//             ˇ
554//             ˇ
555//             ˇfox_jumps ˇover
556//             ˇthe"})
557//             .await;
558//     }
559
560//     #[gpui::test]
561//     async fn test_gg(cx: &mut gpui::TestAppContext) {
562//         let mut cx = NeovimBackedTestContext::new(cx).await;
563//         cx.assert_binding_matches_all(
564//             ["g", "g"],
565//             indoc! {"
566//                 The qˇuick
567
568//                 brown fox jumps
569//                 over ˇthe laˇzy dog"},
570//         )
571//         .await;
572//         cx.assert_binding_matches(
573//             ["g", "g"],
574//             indoc! {"
575
576//                 brown fox jumps
577//                 over the laˇzy dog"},
578//         )
579//         .await;
580//         cx.assert_binding_matches(
581//             ["2", "g", "g"],
582//             indoc! {"
583//                 ˇ
584
585//                 brown fox jumps
586//                 over the lazydog"},
587//         )
588//         .await;
589//     }
590
591//     #[gpui::test]
592//     async fn test_end_of_document(cx: &mut gpui::TestAppContext) {
593//         let mut cx = NeovimBackedTestContext::new(cx).await;
594//         cx.assert_binding_matches_all(
595//             ["shift-g"],
596//             indoc! {"
597//                 The qˇuick
598
599//                 brown fox jumps
600//                 over ˇthe laˇzy dog"},
601//         )
602//         .await;
603//         cx.assert_binding_matches(
604//             ["shift-g"],
605//             indoc! {"
606
607//                 brown fox jumps
608//                 over the laˇzy dog"},
609//         )
610//         .await;
611//         cx.assert_binding_matches(
612//             ["2", "shift-g"],
613//             indoc! {"
614//                 ˇ
615
616//                 brown fox jumps
617//                 over the lazydog"},
618//         )
619//         .await;
620//     }
621
622//     #[gpui::test]
623//     async fn test_a(cx: &mut gpui::TestAppContext) {
624//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["a"]);
625//         cx.assert_all("The qˇuicˇk").await;
626//     }
627
628//     #[gpui::test]
629//     async fn test_insert_end_of_line(cx: &mut gpui::TestAppContext) {
630//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["shift-a"]);
631//         cx.assert_all(indoc! {"
632//             ˇ
633//             The qˇuick
634//             brown ˇfox "})
635//             .await;
636//     }
637
638//     #[gpui::test]
639//     async fn test_jump_to_first_non_whitespace(cx: &mut gpui::TestAppContext) {
640//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["^"]);
641//         cx.assert("The qˇuick").await;
642//         cx.assert(" The qˇuick").await;
643//         cx.assert("ˇ").await;
644//         cx.assert(indoc! {"
645//                 The qˇuick
646//                 brown fox"})
647//             .await;
648//         cx.assert(indoc! {"
649//                 ˇ
650//                 The quick"})
651//             .await;
652//         // Indoc disallows trailing whitespace.
653//         cx.assert("   ˇ \nThe quick").await;
654//     }
655
656//     #[gpui::test]
657//     async fn test_insert_first_non_whitespace(cx: &mut gpui::TestAppContext) {
658//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["shift-i"]);
659//         cx.assert("The qˇuick").await;
660//         cx.assert(" The qˇuick").await;
661//         cx.assert("ˇ").await;
662//         cx.assert(indoc! {"
663//                 The qˇuick
664//                 brown fox"})
665//             .await;
666//         cx.assert(indoc! {"
667//                 ˇ
668//                 The quick"})
669//             .await;
670//     }
671
672//     #[gpui::test]
673//     async fn test_delete_to_end_of_line(cx: &mut gpui::TestAppContext) {
674//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["shift-d"]);
675//         cx.assert(indoc! {"
676//                 The qˇuick
677//                 brown fox"})
678//             .await;
679//         cx.assert(indoc! {"
680//                 The quick
681//                 ˇ
682//                 brown fox"})
683//             .await;
684//     }
685
686//     #[gpui::test]
687//     async fn test_x(cx: &mut gpui::TestAppContext) {
688//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["x"]);
689//         cx.assert_all("ˇTeˇsˇt").await;
690//         cx.assert(indoc! {"
691//                 Tesˇt
692//                 test"})
693//             .await;
694//     }
695
696//     #[gpui::test]
697//     async fn test_delete_left(cx: &mut gpui::TestAppContext) {
698//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["shift-x"]);
699//         cx.assert_all("ˇTˇeˇsˇt").await;
700//         cx.assert(indoc! {"
701//                 Test
702//                 ˇtest"})
703//             .await;
704//     }
705
706//     #[gpui::test]
707//     async fn test_o(cx: &mut gpui::TestAppContext) {
708//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["o"]);
709//         cx.assert("ˇ").await;
710//         cx.assert("The ˇquick").await;
711//         cx.assert_all(indoc! {"
712//                 The qˇuick
713//                 brown ˇfox
714//                 jumps ˇover"})
715//             .await;
716//         cx.assert(indoc! {"
717//                 The quick
718//                 ˇ
719//                 brown fox"})
720//             .await;
721
722//         cx.assert_manual(
723//             indoc! {"
724//                 fn test() {
725//                     println!(ˇ);
726//                 }"},
727//             Mode::Normal,
728//             indoc! {"
729//                 fn test() {
730//                     println!();
731//                     ˇ
732//                 }"},
733//             Mode::Insert,
734//         );
735
736//         cx.assert_manual(
737//             indoc! {"
738//                 fn test(ˇ) {
739//                     println!();
740//                 }"},
741//             Mode::Normal,
742//             indoc! {"
743//                 fn test() {
744//                     ˇ
745//                     println!();
746//                 }"},
747//             Mode::Insert,
748//         );
749//     }
750
751//     #[gpui::test]
752//     async fn test_insert_line_above(cx: &mut gpui::TestAppContext) {
753//         let cx = NeovimBackedTestContext::new(cx).await;
754//         let mut cx = cx.binding(["shift-o"]);
755//         cx.assert("ˇ").await;
756//         cx.assert("The ˇquick").await;
757//         cx.assert_all(indoc! {"
758//             The qˇuick
759//             brown ˇfox
760//             jumps ˇover"})
761//             .await;
762//         cx.assert(indoc! {"
763//             The quick
764//             ˇ
765//             brown fox"})
766//             .await;
767
768//         // Our indentation is smarter than vims. So we don't match here
769//         cx.assert_manual(
770//             indoc! {"
771//                 fn test() {
772//                     println!(ˇ);
773//                 }"},
774//             Mode::Normal,
775//             indoc! {"
776//                 fn test() {
777//                     ˇ
778//                     println!();
779//                 }"},
780//             Mode::Insert,
781//         );
782//         cx.assert_manual(
783//             indoc! {"
784//                 fn test(ˇ) {
785//                     println!();
786//                 }"},
787//             Mode::Normal,
788//             indoc! {"
789//                 ˇ
790//                 fn test() {
791//                     println!();
792//                 }"},
793//             Mode::Insert,
794//         );
795//     }
796
797//     #[gpui::test]
798//     async fn test_dd(cx: &mut gpui::TestAppContext) {
799//         let mut cx = NeovimBackedTestContext::new(cx).await;
800//         cx.assert_neovim_compatible("ˇ", ["d", "d"]).await;
801//         cx.assert_neovim_compatible("The ˇquick", ["d", "d"]).await;
802//         for marked_text in cx.each_marked_position(indoc! {"
803//             The qˇuick
804//             brown ˇfox
805//             jumps ˇover"})
806//         {
807//             cx.assert_neovim_compatible(&marked_text, ["d", "d"]).await;
808//         }
809//         cx.assert_neovim_compatible(
810//             indoc! {"
811//                 The quick
812//                 ˇ
813//                 brown fox"},
814//             ["d", "d"],
815//         )
816//         .await;
817//     }
818
819//     #[gpui::test]
820//     async fn test_cc(cx: &mut gpui::TestAppContext) {
821//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["c", "c"]);
822//         cx.assert("ˇ").await;
823//         cx.assert("The ˇquick").await;
824//         cx.assert_all(indoc! {"
825//                 The quˇick
826//                 brown ˇfox
827//                 jumps ˇover"})
828//             .await;
829//         cx.assert(indoc! {"
830//                 The quick
831//                 ˇ
832//                 brown fox"})
833//             .await;
834//     }
835
836//     #[gpui::test]
837//     async fn test_repeated_word(cx: &mut gpui::TestAppContext) {
838//         let mut cx = NeovimBackedTestContext::new(cx).await;
839
840//         for count in 1..=5 {
841//             cx.assert_binding_matches_all(
842//                 [&count.to_string(), "w"],
843//                 indoc! {"
844//                     ˇThe quˇickˇ browˇn
845//                     ˇ
846//                     ˇfox ˇjumpsˇ-ˇoˇver
847//                     ˇthe lazy dog
848//                 "},
849//             )
850//             .await;
851//         }
852//     }
853
854//     #[gpui::test]
855//     async fn test_h_through_unicode(cx: &mut gpui::TestAppContext) {
856//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["h"]);
857//         cx.assert_all("Testˇ├ˇ──ˇ┐ˇTest").await;
858//     }
859
860//     #[gpui::test]
861//     async fn test_f_and_t(cx: &mut gpui::TestAppContext) {
862//         let mut cx = NeovimBackedTestContext::new(cx).await;
863
864//         for count in 1..=3 {
865//             let test_case = indoc! {"
866//                 ˇaaaˇbˇ ˇbˇ   ˇbˇbˇ aˇaaˇbaaa
867//                 ˇ    ˇbˇaaˇa ˇbˇbˇb
868//                 ˇ
869//                 ˇb
870//             "};
871
872//             cx.assert_binding_matches_all([&count.to_string(), "f", "b"], test_case)
873//                 .await;
874
875//             cx.assert_binding_matches_all([&count.to_string(), "t", "b"], test_case)
876//                 .await;
877//         }
878//     }
879
880//     #[gpui::test]
881//     async fn test_capital_f_and_capital_t(cx: &mut gpui::TestAppContext) {
882//         let mut cx = NeovimBackedTestContext::new(cx).await;
883//         let test_case = indoc! {"
884//             ˇaaaˇbˇ ˇbˇ   ˇbˇbˇ aˇaaˇbaaa
885//             ˇ    ˇbˇaaˇa ˇbˇbˇb
886//             ˇ•••
887//             ˇb
888//             "
889//         };
890
891//         for count in 1..=3 {
892//             cx.assert_binding_matches_all([&count.to_string(), "shift-f", "b"], test_case)
893//                 .await;
894
895//             cx.assert_binding_matches_all([&count.to_string(), "shift-t", "b"], test_case)
896//                 .await;
897//         }
898//     }
899
900//     #[gpui::test]
901//     async fn test_percent(cx: &mut TestAppContext) {
902//         let mut cx = NeovimBackedTestContext::new(cx).await.binding(["%"]);
903//         cx.assert_all("ˇconsole.logˇ(ˇvaˇrˇ)ˇ;").await;
904//         cx.assert_all("ˇconsole.logˇ(ˇ'var', ˇ[ˇ1, ˇ2, 3ˇ]ˇ)ˇ;")
905//             .await;
906//         cx.assert_all("let result = curried_funˇ(ˇ)ˇ(ˇ)ˇ;").await;
907//     }
908// }