test.rs

   1mod neovim_backed_test_context;
   2mod neovim_connection;
   3mod vim_test_context;
   4
   5use std::{sync::Arc, time::Duration};
   6
   7use collections::HashMap;
   8use command_palette::CommandPalette;
   9use editor::{
  10    AnchorRangeExt, DisplayPoint, Editor, EditorMode, MultiBuffer, MultiBufferOffset,
  11    actions::{DeleteLine, WrapSelectionsInTag},
  12    code_context_menus::CodeContextMenu,
  13    display_map::DisplayRow,
  14    test::editor_test_context::EditorTestContext,
  15};
  16use futures::StreamExt;
  17use gpui::{KeyBinding, Modifiers, MouseButton, TestAppContext, px};
  18use itertools::Itertools;
  19use language::{CursorShape, Language, LanguageConfig, Point};
  20pub use neovim_backed_test_context::*;
  21use settings::SettingsStore;
  22use ui::Pixels;
  23use util::{path, test::marked_text_ranges};
  24pub use vim_test_context::*;
  25
  26use gpui::VisualTestContext;
  27use indoc::indoc;
  28use project::FakeFs;
  29use search::BufferSearchBar;
  30use search::{ProjectSearchView, project_search};
  31use serde_json::json;
  32use workspace::{DeploySearch, MultiWorkspace};
  33
  34use crate::{PushSneak, PushSneakBackward, VimAddon, insert::NormalBefore, motion, state::Mode};
  35
  36use util_macros::perf;
  37
  38#[perf]
  39#[gpui::test]
  40async fn test_initially_disabled(cx: &mut gpui::TestAppContext) {
  41    let mut cx = VimTestContext::new(cx, false).await;
  42    cx.simulate_keystrokes("h j k l");
  43    cx.assert_editor_state("hjklˇ");
  44}
  45
  46#[perf]
  47#[gpui::test]
  48async fn test_neovim(cx: &mut gpui::TestAppContext) {
  49    let mut cx = NeovimBackedTestContext::new(cx).await;
  50
  51    cx.simulate_shared_keystrokes("i").await;
  52    cx.shared_state().await.assert_matches();
  53    cx.simulate_shared_keystrokes("shift-t e s t space t e s t escape 0 d w")
  54        .await;
  55    cx.shared_state().await.assert_matches();
  56    cx.assert_editor_state("ˇtest");
  57}
  58
  59#[perf]
  60#[gpui::test]
  61async fn test_toggle_through_settings(cx: &mut gpui::TestAppContext) {
  62    let mut cx = VimTestContext::new(cx, true).await;
  63
  64    cx.simulate_keystrokes("i");
  65    assert_eq!(cx.mode(), Mode::Insert);
  66
  67    // Editor acts as though vim is disabled
  68    cx.disable_vim();
  69    cx.simulate_keystrokes("h j k l");
  70    cx.assert_editor_state("hjklˇ");
  71
  72    // Selections aren't changed if editor is blurred but vim-mode is still disabled.
  73    cx.cx.set_state("«hjklˇ»");
  74    cx.assert_editor_state("«hjklˇ»");
  75    cx.update_editor(|_, window, _cx| window.blur());
  76    cx.assert_editor_state("«hjklˇ»");
  77    cx.update_editor(|_, window, cx| cx.focus_self(window));
  78    cx.assert_editor_state("«hjklˇ»");
  79
  80    // Enabling dynamically sets vim mode again and restores normal mode
  81    cx.enable_vim();
  82    assert_eq!(cx.mode(), Mode::Normal);
  83    cx.simulate_keystrokes("h h h l");
  84    assert_eq!(cx.buffer_text(), "hjkl".to_owned());
  85    cx.assert_editor_state("hˇjkl");
  86    cx.simulate_keystrokes("i T e s t");
  87    cx.assert_editor_state("hTestˇjkl");
  88
  89    // Disabling and enabling resets to normal mode
  90    assert_eq!(cx.mode(), Mode::Insert);
  91    cx.disable_vim();
  92    cx.enable_vim();
  93    assert_eq!(cx.mode(), Mode::Normal);
  94}
  95
  96#[perf]
  97#[gpui::test]
  98async fn test_vim_linked_edits_delete_x(app_cx: &mut gpui::TestAppContext) {
  99    let mut cx = VimTestContext::new_html(app_cx).await;
 100
 101    cx.set_state("<diˇv></div>", Mode::Normal);
 102    cx.update_editor(|editor, _window, cx| {
 103        editor
 104            .set_linked_edit_ranges_for_testing(
 105                vec![(
 106                    Point::new(0, 1)..Point::new(0, 4),
 107                    vec![Point::new(0, 7)..Point::new(0, 10)],
 108                )],
 109                cx,
 110            )
 111            .expect("linked edit ranges should be set");
 112    });
 113
 114    cx.simulate_keystrokes("x");
 115    cx.assert_editor_state("<diˇ></di>");
 116}
 117
 118#[perf]
 119#[gpui::test]
 120async fn test_vim_linked_edits_change_iw(app_cx: &mut gpui::TestAppContext) {
 121    let mut cx = VimTestContext::new_html(app_cx).await;
 122
 123    cx.set_state("<diˇv></div>", Mode::Normal);
 124    cx.update_editor(|editor, _window, cx| {
 125        editor
 126            .set_linked_edit_ranges_for_testing(
 127                vec![(
 128                    Point::new(0, 1)..Point::new(0, 4),
 129                    vec![Point::new(0, 7)..Point::new(0, 10)],
 130                )],
 131                cx,
 132            )
 133            .expect("linked edit ranges should be set");
 134    });
 135
 136    cx.simulate_keystrokes("c i w s p a n escape");
 137    cx.assert_editor_state("<spaˇn></span>");
 138}
 139
 140#[perf]
 141#[gpui::test]
 142async fn test_vim_linked_edits_substitute_s(app_cx: &mut gpui::TestAppContext) {
 143    let mut cx = VimTestContext::new_html(app_cx).await;
 144
 145    cx.set_state("<diˇv></div>", Mode::Normal);
 146    cx.update_editor(|editor, _window, cx| {
 147        editor
 148            .set_linked_edit_ranges_for_testing(
 149                vec![(
 150                    Point::new(0, 1)..Point::new(0, 4),
 151                    vec![Point::new(0, 7)..Point::new(0, 10)],
 152                )],
 153                cx,
 154            )
 155            .expect("linked edit ranges should be set");
 156    });
 157
 158    cx.simulate_keystrokes("s s p a n escape");
 159    cx.assert_editor_state("<dispaˇn></dispan>");
 160}
 161
 162#[perf]
 163#[gpui::test]
 164async fn test_vim_linked_edits_visual_change(app_cx: &mut gpui::TestAppContext) {
 165    let mut cx = VimTestContext::new_html(app_cx).await;
 166
 167    cx.set_state("<diˇv></div>", Mode::Normal);
 168    cx.update_editor(|editor, _window, cx| {
 169        editor
 170            .set_linked_edit_ranges_for_testing(
 171                vec![(
 172                    Point::new(0, 1)..Point::new(0, 4),
 173                    vec![Point::new(0, 7)..Point::new(0, 10)],
 174                )],
 175                cx,
 176            )
 177            .expect("linked edit ranges should be set");
 178    });
 179
 180    // Visual change routes through substitute; visual `s` shares this path.
 181    cx.simulate_keystrokes("v i w c s p a n escape");
 182    cx.assert_editor_state("<spaˇn></span>");
 183}
 184
 185#[perf]
 186#[gpui::test]
 187async fn test_vim_linked_edits_visual_substitute_s(app_cx: &mut gpui::TestAppContext) {
 188    let mut cx = VimTestContext::new_html(app_cx).await;
 189
 190    cx.set_state("<diˇv></div>", Mode::Normal);
 191    cx.update_editor(|editor, _window, cx| {
 192        editor
 193            .set_linked_edit_ranges_for_testing(
 194                vec![(
 195                    Point::new(0, 1)..Point::new(0, 4),
 196                    vec![Point::new(0, 7)..Point::new(0, 10)],
 197                )],
 198                cx,
 199            )
 200            .expect("linked edit ranges should be set");
 201    });
 202
 203    cx.simulate_keystrokes("v i w s s p a n escape");
 204    cx.assert_editor_state("<spaˇn></span>");
 205}
 206
 207#[perf]
 208#[gpui::test]
 209async fn test_cancel_selection(cx: &mut gpui::TestAppContext) {
 210    let mut cx = VimTestContext::new(cx, true).await;
 211
 212    cx.set_state(
 213        indoc! {"The quick brown fox juˇmps over the lazy dog"},
 214        Mode::Normal,
 215    );
 216    // jumps
 217    cx.simulate_keystrokes("v l l");
 218    cx.assert_editor_state("The quick brown fox ju«mpsˇ» over the lazy dog");
 219
 220    cx.simulate_keystrokes("escape");
 221    cx.assert_editor_state("The quick brown fox jumpˇs over the lazy dog");
 222
 223    // go back to the same selection state
 224    cx.simulate_keystrokes("v h h");
 225    cx.assert_editor_state("The quick brown fox ju«ˇmps» over the lazy dog");
 226
 227    // Ctrl-[ should behave like Esc
 228    cx.simulate_keystrokes("ctrl-[");
 229    cx.assert_editor_state("The quick brown fox juˇmps over the lazy dog");
 230}
 231
 232#[perf]
 233#[gpui::test]
 234async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
 235    let mut cx = VimTestContext::new(cx, true).await;
 236
 237    cx.set_state(
 238        indoc! {"
 239            The quick brown
 240            fox juˇmps over
 241            the lazy dog"},
 242        Mode::Normal,
 243    );
 244    cx.simulate_keystrokes("/");
 245
 246    let search_bar = cx.workspace(|workspace, _, cx| {
 247        workspace
 248            .active_pane()
 249            .read(cx)
 250            .toolbar()
 251            .read(cx)
 252            .item_of_type::<BufferSearchBar>()
 253            .expect("Buffer search bar should be deployed")
 254    });
 255
 256    cx.update_entity(search_bar, |bar, _, cx| {
 257        assert_eq!(bar.query(cx), "");
 258    })
 259}
 260
 261#[perf]
 262#[gpui::test]
 263async fn test_count_down(cx: &mut gpui::TestAppContext) {
 264    let mut cx = VimTestContext::new(cx, true).await;
 265
 266    cx.set_state(indoc! {"aˇa\nbb\ncc\ndd\nee"}, Mode::Normal);
 267    cx.simulate_keystrokes("2 down");
 268    cx.assert_editor_state("aa\nbb\ncˇc\ndd\nee");
 269    cx.simulate_keystrokes("9 down");
 270    cx.assert_editor_state("aa\nbb\ncc\ndd\neˇe");
 271}
 272
 273#[perf]
 274#[gpui::test]
 275async fn test_end_of_document_710(cx: &mut gpui::TestAppContext) {
 276    let mut cx = VimTestContext::new(cx, true).await;
 277
 278    // goes to end by default
 279    cx.set_state(indoc! {"aˇa\nbb\ncc"}, Mode::Normal);
 280    cx.simulate_keystrokes("shift-g");
 281    cx.assert_editor_state("aa\nbb\ncˇc");
 282
 283    // can go to line 1 (https://github.com/zed-industries/zed/issues/5812)
 284    cx.simulate_keystrokes("1 shift-g");
 285    cx.assert_editor_state("aˇa\nbb\ncc");
 286}
 287
 288#[perf]
 289#[gpui::test]
 290async fn test_end_of_line_with_times(cx: &mut gpui::TestAppContext) {
 291    let mut cx = VimTestContext::new(cx, true).await;
 292
 293    // goes to current line end
 294    cx.set_state(indoc! {"ˇaa\nbb\ncc"}, Mode::Normal);
 295    cx.simulate_keystrokes("$");
 296    cx.assert_editor_state("aˇa\nbb\ncc");
 297
 298    // goes to next line end
 299    cx.simulate_keystrokes("2 $");
 300    cx.assert_editor_state("aa\nbˇb\ncc");
 301
 302    // try to exceed the final line.
 303    cx.simulate_keystrokes("4 $");
 304    cx.assert_editor_state("aa\nbb\ncˇc");
 305}
 306
 307#[perf]
 308#[gpui::test]
 309async fn test_indent_outdent(cx: &mut gpui::TestAppContext) {
 310    let mut cx = VimTestContext::new(cx, true).await;
 311
 312    // works in normal mode
 313    cx.set_state(indoc! {"aa\nbˇb\ncc"}, Mode::Normal);
 314    cx.simulate_keystrokes("> >");
 315    cx.assert_editor_state("aa\n    bˇb\ncc");
 316    cx.simulate_keystrokes("< <");
 317    cx.assert_editor_state("aa\nbˇb\ncc");
 318
 319    // works in visual mode
 320    cx.simulate_keystrokes("shift-v down >");
 321    cx.assert_editor_state("aa\n    bˇb\n    cc");
 322
 323    // works as operator
 324    cx.set_state("aa\nbˇb\ncc\n", Mode::Normal);
 325    cx.simulate_keystrokes("> j");
 326    cx.assert_editor_state("aa\n    bˇb\n    cc\n");
 327    cx.simulate_keystrokes("< k");
 328    cx.assert_editor_state("aa\nbˇb\n    cc\n");
 329    cx.simulate_keystrokes("> i p");
 330    cx.assert_editor_state("    aa\n    bˇb\n        cc\n");
 331    cx.simulate_keystrokes("< i p");
 332    cx.assert_editor_state("aa\nbˇb\n    cc\n");
 333    cx.simulate_keystrokes("< i p");
 334    cx.assert_editor_state("aa\nbˇb\ncc\n");
 335
 336    cx.set_state("ˇaa\nbb\ncc\n", Mode::Normal);
 337    cx.simulate_keystrokes("> 2 j");
 338    cx.assert_editor_state("    ˇaa\n    bb\n    cc\n");
 339
 340    cx.set_state("aa\nbb\nˇcc\n", Mode::Normal);
 341    cx.simulate_keystrokes("> 2 k");
 342    cx.assert_editor_state("    aa\n    bb\n    ˇcc\n");
 343
 344    // works with repeat
 345    cx.set_state("a\nb\nccˇc\n", Mode::Normal);
 346    cx.simulate_keystrokes("> 2 k");
 347    cx.assert_editor_state("    a\n    b\n    ccˇc\n");
 348    cx.simulate_keystrokes(".");
 349    cx.assert_editor_state("        a\n        b\n        ccˇc\n");
 350    cx.simulate_keystrokes("v k <");
 351    cx.assert_editor_state("        a\n\n    ccc\n");
 352    cx.simulate_keystrokes(".");
 353    cx.assert_editor_state("        a\n\nccc\n");
 354}
 355
 356#[perf]
 357#[gpui::test]
 358async fn test_escape_command_palette(cx: &mut gpui::TestAppContext) {
 359    let mut cx = VimTestContext::new(cx, true).await;
 360
 361    cx.set_state("aˇbc\n", Mode::Normal);
 362    cx.simulate_keystrokes("i cmd-shift-p");
 363
 364    assert!(
 365        cx.workspace(|workspace, _, cx| workspace.active_modal::<CommandPalette>(cx).is_some())
 366    );
 367    cx.simulate_keystrokes("escape");
 368    cx.run_until_parked();
 369    assert!(
 370        !cx.workspace(|workspace, _, cx| workspace.active_modal::<CommandPalette>(cx).is_some())
 371    );
 372    cx.assert_state("aˇbc\n", Mode::Insert);
 373}
 374
 375#[perf]
 376#[gpui::test]
 377async fn test_escape_cancels(cx: &mut gpui::TestAppContext) {
 378    let mut cx = VimTestContext::new(cx, true).await;
 379
 380    cx.set_state("aˇbˇc", Mode::Normal);
 381    cx.simulate_keystrokes("escape");
 382
 383    cx.assert_state("aˇbc", Mode::Normal);
 384}
 385
 386#[perf]
 387#[gpui::test]
 388async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
 389    let mut cx = VimTestContext::new(cx, true).await;
 390
 391    cx.set_state(indoc! {"aa\nbˇb\ncc\ncc\ncc\n"}, Mode::Normal);
 392    cx.simulate_keystrokes("/ c c");
 393
 394    let search_bar = cx.workspace(|workspace, _, cx| {
 395        workspace
 396            .active_pane()
 397            .read(cx)
 398            .toolbar()
 399            .read(cx)
 400            .item_of_type::<BufferSearchBar>()
 401            .expect("Buffer search bar should be deployed")
 402    });
 403
 404    cx.update_entity(search_bar, |bar, _, cx| {
 405        assert_eq!(bar.query(cx), "cc");
 406    });
 407
 408    cx.update_editor(|editor, window, cx| {
 409        let highlights = editor.all_text_background_highlights(window, cx);
 410        assert_eq!(3, highlights.len());
 411        assert_eq!(
 412            DisplayPoint::new(DisplayRow(2), 0)..DisplayPoint::new(DisplayRow(2), 2),
 413            highlights[0].0
 414        )
 415    });
 416    cx.simulate_keystrokes("enter");
 417
 418    cx.assert_state(indoc! {"aa\nbb\nˇcc\ncc\ncc\n"}, Mode::Normal);
 419    cx.simulate_keystrokes("n");
 420    cx.assert_state(indoc! {"aa\nbb\ncc\nˇcc\ncc\n"}, Mode::Normal);
 421    cx.simulate_keystrokes("shift-n");
 422    cx.assert_state(indoc! {"aa\nbb\nˇcc\ncc\ncc\n"}, Mode::Normal);
 423}
 424
 425#[perf]
 426#[gpui::test]
 427async fn test_word_characters(cx: &mut gpui::TestAppContext) {
 428    let mut cx = VimTestContext::new_typescript(cx).await;
 429    cx.set_state(
 430        indoc! { "
 431        class A {
 432            #ˇgoop = 99;
 433            $ˇgoop () { return this.#gˇoop };
 434        };
 435        console.log(new A().$gooˇp())
 436    "},
 437        Mode::Normal,
 438    );
 439    cx.simulate_keystrokes("v i w");
 440    cx.assert_state(
 441        indoc! {"
 442        class A {
 443            «#goopˇ» = 99;
 444            «$goopˇ» () { return this.«#goopˇ» };
 445        };
 446        console.log(new A().«$goopˇ»())
 447    "},
 448        Mode::Visual,
 449    )
 450}
 451
 452#[perf]
 453#[gpui::test]
 454async fn test_kebab_case(cx: &mut gpui::TestAppContext) {
 455    let mut cx = VimTestContext::new_html(cx).await;
 456    cx.set_state(
 457        indoc! { r#"
 458            <div><a class="bg-rˇed"></a></div>
 459            "#},
 460        Mode::Normal,
 461    );
 462    cx.simulate_keystrokes("v i w");
 463    cx.assert_state(
 464        indoc! { r#"
 465        <div><a class="bg-«redˇ»"></a></div>
 466        "#
 467        },
 468        Mode::Visual,
 469    )
 470}
 471
 472#[perf]
 473#[gpui::test]
 474async fn test_join_lines(cx: &mut gpui::TestAppContext) {
 475    let mut cx = NeovimBackedTestContext::new(cx).await;
 476
 477    cx.set_shared_state(indoc! {"
 478      ˇone
 479      two
 480      three
 481      four
 482      five
 483      six
 484      "})
 485        .await;
 486    cx.simulate_shared_keystrokes("shift-j").await;
 487    cx.shared_state().await.assert_eq(indoc! {"
 488          oneˇ two
 489          three
 490          four
 491          five
 492          six
 493          "});
 494    cx.simulate_shared_keystrokes("3 shift-j").await;
 495    cx.shared_state().await.assert_eq(indoc! {"
 496          one two threeˇ four
 497          five
 498          six
 499          "});
 500
 501    cx.set_shared_state(indoc! {"
 502      ˇone
 503      two
 504      three
 505      four
 506      five
 507      six
 508      "})
 509        .await;
 510    cx.simulate_shared_keystrokes("j v 3 j shift-j").await;
 511    cx.shared_state().await.assert_eq(indoc! {"
 512      one
 513      two three fourˇ five
 514      six
 515      "});
 516
 517    cx.set_shared_state(indoc! {"
 518      ˇone
 519      two
 520      three
 521      four
 522      five
 523      six
 524      "})
 525        .await;
 526    cx.simulate_shared_keystrokes("g shift-j").await;
 527    cx.shared_state().await.assert_eq(indoc! {"
 528          oneˇtwo
 529          three
 530          four
 531          five
 532          six
 533          "});
 534    cx.simulate_shared_keystrokes("3 g shift-j").await;
 535    cx.shared_state().await.assert_eq(indoc! {"
 536          onetwothreeˇfour
 537          five
 538          six
 539          "});
 540
 541    cx.set_shared_state(indoc! {"
 542      ˇone
 543      two
 544      three
 545      four
 546      five
 547      six
 548      "})
 549        .await;
 550    cx.simulate_shared_keystrokes("j v 3 j g shift-j").await;
 551    cx.shared_state().await.assert_eq(indoc! {"
 552      one
 553      twothreefourˇfive
 554      six
 555      "});
 556}
 557
 558#[cfg(target_os = "macos")]
 559#[perf]
 560#[gpui::test]
 561async fn test_wrapped_lines(cx: &mut gpui::TestAppContext) {
 562    let mut cx = NeovimBackedTestContext::new(cx).await;
 563
 564    cx.set_shared_wrap(12).await;
 565    // tests line wrap as follows:
 566    //  1: twelve char
 567    //     twelve char
 568    //  2: twelve char
 569    cx.set_shared_state(indoc! { "
 570        tˇwelve char twelve char
 571        twelve char
 572    "})
 573        .await;
 574    cx.simulate_shared_keystrokes("j").await;
 575    cx.shared_state().await.assert_eq(indoc! {"
 576        twelve char twelve char
 577        tˇwelve char
 578    "});
 579    cx.simulate_shared_keystrokes("k").await;
 580    cx.shared_state().await.assert_eq(indoc! {"
 581        tˇwelve char twelve char
 582        twelve char
 583    "});
 584    cx.simulate_shared_keystrokes("g j").await;
 585    cx.shared_state().await.assert_eq(indoc! {"
 586        twelve char tˇwelve char
 587        twelve char
 588    "});
 589    cx.simulate_shared_keystrokes("g j").await;
 590    cx.shared_state().await.assert_eq(indoc! {"
 591        twelve char twelve char
 592        tˇwelve char
 593    "});
 594
 595    cx.simulate_shared_keystrokes("g k").await;
 596    cx.shared_state().await.assert_eq(indoc! {"
 597        twelve char tˇwelve char
 598        twelve char
 599    "});
 600
 601    cx.simulate_shared_keystrokes("g ^").await;
 602    cx.shared_state().await.assert_eq(indoc! {"
 603        twelve char ˇtwelve char
 604        twelve char
 605    "});
 606
 607    cx.simulate_shared_keystrokes("^").await;
 608    cx.shared_state().await.assert_eq(indoc! {"
 609        ˇtwelve char twelve char
 610        twelve char
 611    "});
 612
 613    cx.simulate_shared_keystrokes("g $").await;
 614    cx.shared_state().await.assert_eq(indoc! {"
 615        twelve charˇ twelve char
 616        twelve char
 617    "});
 618    cx.simulate_shared_keystrokes("$").await;
 619    cx.shared_state().await.assert_eq(indoc! {"
 620        twelve char twelve chaˇr
 621        twelve char
 622    "});
 623
 624    cx.set_shared_state(indoc! { "
 625        tˇwelve char twelve char
 626        twelve char
 627    "})
 628        .await;
 629    cx.simulate_shared_keystrokes("enter").await;
 630    cx.shared_state().await.assert_eq(indoc! {"
 631            twelve char twelve char
 632            ˇtwelve char
 633        "});
 634
 635    cx.set_shared_state(indoc! { "
 636        twelve char
 637        tˇwelve char twelve char
 638        twelve char
 639    "})
 640        .await;
 641    cx.simulate_shared_keystrokes("o o escape").await;
 642    cx.shared_state().await.assert_eq(indoc! {"
 643        twelve char
 644        twelve char twelve char
 645        ˇo
 646        twelve char
 647    "});
 648
 649    cx.set_shared_state(indoc! { "
 650        twelve char
 651        tˇwelve char twelve char
 652        twelve char
 653    "})
 654        .await;
 655    cx.simulate_shared_keystrokes("shift-a a escape").await;
 656    cx.shared_state().await.assert_eq(indoc! {"
 657        twelve char
 658        twelve char twelve charˇa
 659        twelve char
 660    "});
 661    cx.simulate_shared_keystrokes("shift-i i escape").await;
 662    cx.shared_state().await.assert_eq(indoc! {"
 663        twelve char
 664        ˇitwelve char twelve chara
 665        twelve char
 666    "});
 667    cx.simulate_shared_keystrokes("shift-d").await;
 668    cx.shared_state().await.assert_eq(indoc! {"
 669        twelve char
 670        ˇ
 671        twelve char
 672    "});
 673
 674    cx.set_shared_state(indoc! { "
 675        twelve char
 676        twelve char tˇwelve char
 677        twelve char
 678    "})
 679        .await;
 680    cx.simulate_shared_keystrokes("shift-o o escape").await;
 681    cx.shared_state().await.assert_eq(indoc! {"
 682        twelve char
 683        ˇo
 684        twelve char twelve char
 685        twelve char
 686    "});
 687
 688    // line wraps as:
 689    // fourteen ch
 690    // ar
 691    // fourteen ch
 692    // ar
 693    cx.set_shared_state(indoc! { "
 694        fourteen chaˇr
 695        fourteen char
 696    "})
 697        .await;
 698
 699    cx.simulate_shared_keystrokes("d i w").await;
 700    cx.shared_state().await.assert_eq(indoc! {"
 701        fourteenˇ•
 702        fourteen char
 703    "});
 704    cx.simulate_shared_keystrokes("j shift-f e f r").await;
 705    cx.shared_state().await.assert_eq(indoc! {"
 706        fourteen•
 707        fourteen chaˇr
 708    "});
 709}
 710
 711#[perf]
 712#[gpui::test]
 713async fn test_folds(cx: &mut gpui::TestAppContext) {
 714    let mut cx = NeovimBackedTestContext::new(cx).await;
 715    cx.set_neovim_option("foldmethod=manual").await;
 716
 717    cx.set_shared_state(indoc! { "
 718        fn boop() {
 719          ˇbarp()
 720          bazp()
 721        }
 722    "})
 723        .await;
 724    cx.simulate_shared_keystrokes("shift-v j z f").await;
 725
 726    // visual display is now:
 727    // fn boop () {
 728    //  [FOLDED]
 729    // }
 730
 731    // TODO: this should not be needed but currently zf does not
 732    // return to normal mode.
 733    cx.simulate_shared_keystrokes("escape").await;
 734
 735    // skip over fold downward
 736    cx.simulate_shared_keystrokes("g g").await;
 737    cx.shared_state().await.assert_eq(indoc! {"
 738        ˇfn boop() {
 739          barp()
 740          bazp()
 741        }
 742    "});
 743
 744    cx.simulate_shared_keystrokes("j j").await;
 745    cx.shared_state().await.assert_eq(indoc! {"
 746        fn boop() {
 747          barp()
 748          bazp()
 749        ˇ}
 750    "});
 751
 752    // skip over fold upward
 753    cx.simulate_shared_keystrokes("2 k").await;
 754    cx.shared_state().await.assert_eq(indoc! {"
 755        ˇfn boop() {
 756          barp()
 757          bazp()
 758        }
 759    "});
 760
 761    // yank the fold
 762    cx.simulate_shared_keystrokes("down y y").await;
 763    cx.shared_clipboard()
 764        .await
 765        .assert_eq("  barp()\n  bazp()\n");
 766
 767    // re-open
 768    cx.simulate_shared_keystrokes("z o").await;
 769    cx.shared_state().await.assert_eq(indoc! {"
 770        fn boop() {
 771        ˇ  barp()
 772          bazp()
 773        }
 774    "});
 775}
 776
 777#[perf]
 778#[gpui::test]
 779async fn test_folds_panic(cx: &mut gpui::TestAppContext) {
 780    let mut cx = NeovimBackedTestContext::new(cx).await;
 781    cx.set_neovim_option("foldmethod=manual").await;
 782
 783    cx.set_shared_state(indoc! { "
 784        fn boop() {
 785          ˇbarp()
 786          bazp()
 787        }
 788    "})
 789        .await;
 790    cx.simulate_shared_keystrokes("shift-v j z f").await;
 791    cx.simulate_shared_keystrokes("escape").await;
 792    cx.simulate_shared_keystrokes("g g").await;
 793    cx.simulate_shared_keystrokes("5 d j").await;
 794    cx.shared_state().await.assert_eq("ˇ");
 795    cx.set_shared_state(indoc! {"
 796        fn boop() {
 797          ˇbarp()
 798          bazp()
 799        }
 800    "})
 801        .await;
 802    cx.simulate_shared_keystrokes("shift-v j j z f").await;
 803    cx.simulate_shared_keystrokes("escape").await;
 804    cx.simulate_shared_keystrokes("shift-g shift-v").await;
 805    cx.shared_state().await.assert_eq(indoc! {"
 806        fn boop() {
 807          barp()
 808          bazp()
 809        }
 810        ˇ"});
 811}
 812
 813#[perf]
 814#[gpui::test]
 815async fn test_clear_counts(cx: &mut gpui::TestAppContext) {
 816    let mut cx = NeovimBackedTestContext::new(cx).await;
 817
 818    cx.set_shared_state(indoc! {"
 819        The quick brown
 820        fox juˇmps over
 821        the lazy dog"})
 822        .await;
 823
 824    cx.simulate_shared_keystrokes("4 escape 3 d l").await;
 825    cx.shared_state().await.assert_eq(indoc! {"
 826        The quick brown
 827        fox juˇ over
 828        the lazy dog"});
 829}
 830
 831#[perf]
 832#[gpui::test]
 833async fn test_zero(cx: &mut gpui::TestAppContext) {
 834    let mut cx = NeovimBackedTestContext::new(cx).await;
 835
 836    cx.set_shared_state(indoc! {"
 837        The quˇick brown
 838        fox jumps over
 839        the lazy dog"})
 840        .await;
 841
 842    cx.simulate_shared_keystrokes("0").await;
 843    cx.shared_state().await.assert_eq(indoc! {"
 844        ˇThe quick brown
 845        fox jumps over
 846        the lazy dog"});
 847
 848    cx.simulate_shared_keystrokes("1 0 l").await;
 849    cx.shared_state().await.assert_eq(indoc! {"
 850        The quick ˇbrown
 851        fox jumps over
 852        the lazy dog"});
 853}
 854
 855#[perf]
 856#[gpui::test]
 857async fn test_selection_goal(cx: &mut gpui::TestAppContext) {
 858    let mut cx = NeovimBackedTestContext::new(cx).await;
 859
 860    cx.set_shared_state(indoc! {"
 861        ;;ˇ;
 862        Lorem Ipsum"})
 863        .await;
 864
 865    cx.simulate_shared_keystrokes("a down up ; down up").await;
 866    cx.shared_state().await.assert_eq(indoc! {"
 867        ;;;;ˇ
 868        Lorem Ipsum"});
 869}
 870
 871#[cfg(target_os = "macos")]
 872#[perf]
 873#[gpui::test]
 874async fn test_wrapped_motions(cx: &mut gpui::TestAppContext) {
 875    let mut cx = NeovimBackedTestContext::new(cx).await;
 876
 877    cx.set_shared_wrap(12).await;
 878
 879    cx.set_shared_state(indoc! {"
 880                aaˇaa
 881                😃😃"
 882    })
 883    .await;
 884    cx.simulate_shared_keystrokes("j").await;
 885    cx.shared_state().await.assert_eq(indoc! {"
 886                aaaa
 887                😃ˇ😃"
 888    });
 889
 890    cx.set_shared_state(indoc! {"
 891                123456789012aaˇaa
 892                123456789012😃😃"
 893    })
 894    .await;
 895    cx.simulate_shared_keystrokes("j").await;
 896    cx.shared_state().await.assert_eq(indoc! {"
 897        123456789012aaaa
 898        123456789012😃ˇ😃"
 899    });
 900
 901    cx.set_shared_state(indoc! {"
 902                123456789012aaˇaa
 903                123456789012😃😃"
 904    })
 905    .await;
 906    cx.simulate_shared_keystrokes("j").await;
 907    cx.shared_state().await.assert_eq(indoc! {"
 908        123456789012aaaa
 909        123456789012😃ˇ😃"
 910    });
 911
 912    cx.set_shared_state(indoc! {"
 913        123456789012aaaaˇaaaaaaaa123456789012
 914        wow
 915        123456789012😃😃😃😃😃😃123456789012"
 916    })
 917    .await;
 918    cx.simulate_shared_keystrokes("j j").await;
 919    cx.shared_state().await.assert_eq(indoc! {"
 920        123456789012aaaaaaaaaaaa123456789012
 921        wow
 922        123456789012😃😃ˇ😃😃😃😃123456789012"
 923    });
 924}
 925
 926#[perf]
 927#[gpui::test]
 928async fn test_wrapped_delete_end_document(cx: &mut gpui::TestAppContext) {
 929    let mut cx = NeovimBackedTestContext::new(cx).await;
 930
 931    cx.set_shared_wrap(12).await;
 932
 933    cx.set_shared_state(indoc! {"
 934                aaˇaaaaaaaaaaaaaaaaaa
 935                bbbbbbbbbbbbbbbbbbbb
 936                cccccccccccccccccccc"
 937    })
 938    .await;
 939    cx.simulate_shared_keystrokes("d shift-g i z z z").await;
 940    cx.shared_state().await.assert_eq(indoc! {"
 941                zzzˇ"
 942    });
 943}
 944
 945#[perf]
 946#[gpui::test]
 947async fn test_paragraphs_dont_wrap(cx: &mut gpui::TestAppContext) {
 948    let mut cx = NeovimBackedTestContext::new(cx).await;
 949
 950    cx.set_shared_state(indoc! {"
 951        one
 952        ˇ
 953        two"})
 954        .await;
 955
 956    cx.simulate_shared_keystrokes("} }").await;
 957    cx.shared_state().await.assert_eq(indoc! {"
 958        one
 959
 960        twˇo"});
 961
 962    cx.simulate_shared_keystrokes("{ { {").await;
 963    cx.shared_state().await.assert_eq(indoc! {"
 964        ˇone
 965
 966        two"});
 967}
 968
 969#[perf]
 970#[gpui::test]
 971async fn test_select_all_issue_2170(cx: &mut gpui::TestAppContext) {
 972    let mut cx = VimTestContext::new(cx, true).await;
 973
 974    cx.set_state(
 975        indoc! {"
 976        defmodule Test do
 977            def test(a, ˇ[_, _] = b), do: IO.puts('hi')
 978        end
 979    "},
 980        Mode::Normal,
 981    );
 982    cx.simulate_keystrokes("g a");
 983    cx.assert_state(
 984        indoc! {"
 985        defmodule Test do
 986            def test(a, «[ˇ»_, _] = b), do: IO.puts('hi')
 987        end
 988    "},
 989        Mode::Visual,
 990    );
 991}
 992
 993#[perf]
 994#[gpui::test]
 995async fn test_jk(cx: &mut gpui::TestAppContext) {
 996    let mut cx = NeovimBackedTestContext::new(cx).await;
 997
 998    cx.update(|_, cx| {
 999        cx.bind_keys([KeyBinding::new(
1000            "j k",
1001            NormalBefore,
1002            Some("vim_mode == insert"),
1003        )])
1004    });
1005    cx.neovim.exec("imap jk <esc>").await;
1006
1007    cx.set_shared_state("ˇhello").await;
1008    cx.simulate_shared_keystrokes("i j o j k").await;
1009    cx.shared_state().await.assert_eq("jˇohello");
1010}
1011
1012fn assert_pending_input(cx: &mut VimTestContext, expected: &str) {
1013    cx.update_editor(|editor, window, cx| {
1014        let snapshot = editor.snapshot(window, cx);
1015        let highlights = editor
1016            .text_highlights(editor::HighlightKey::PendingInput, cx)
1017            .unwrap()
1018            .1;
1019        let (_, ranges) = marked_text_ranges(expected, false);
1020
1021        assert_eq!(
1022            highlights
1023                .iter()
1024                .map(|highlight| highlight.to_offset(&snapshot.buffer_snapshot()))
1025                .collect::<Vec<_>>(),
1026            ranges
1027                .iter()
1028                .map(|range| MultiBufferOffset(range.start)..MultiBufferOffset(range.end))
1029                .collect::<Vec<_>>()
1030        )
1031    });
1032}
1033
1034#[perf]
1035#[gpui::test]
1036async fn test_jk_multi(cx: &mut gpui::TestAppContext) {
1037    let mut cx = VimTestContext::new(cx, true).await;
1038
1039    cx.update(|_, cx| {
1040        cx.bind_keys([KeyBinding::new(
1041            "j k l",
1042            NormalBefore,
1043            Some("vim_mode == insert"),
1044        )])
1045    });
1046
1047    cx.set_state("ˇone ˇone ˇone", Mode::Normal);
1048    cx.simulate_keystrokes("i j");
1049    cx.simulate_keystrokes("k");
1050    cx.assert_state("ˇjkone ˇjkone ˇjkone", Mode::Insert);
1051    assert_pending_input(&mut cx, "«jk»one «jk»one «jk»one");
1052    cx.simulate_keystrokes("o j k");
1053    cx.assert_state("jkoˇjkone jkoˇjkone jkoˇjkone", Mode::Insert);
1054    assert_pending_input(&mut cx, "jko«jk»one jko«jk»one jko«jk»one");
1055    cx.simulate_keystrokes("l");
1056    cx.assert_state("jkˇoone jkˇoone jkˇoone", Mode::Normal);
1057}
1058
1059#[perf]
1060#[gpui::test]
1061async fn test_jk_delay(cx: &mut gpui::TestAppContext) {
1062    let mut cx = VimTestContext::new(cx, true).await;
1063
1064    cx.update(|_, cx| {
1065        cx.bind_keys([KeyBinding::new(
1066            "j k",
1067            NormalBefore,
1068            Some("vim_mode == insert"),
1069        )])
1070    });
1071
1072    cx.set_state("ˇhello", Mode::Normal);
1073    cx.simulate_keystrokes("i j");
1074    cx.executor().advance_clock(Duration::from_millis(500));
1075    cx.run_until_parked();
1076    cx.assert_state("ˇjhello", Mode::Insert);
1077    cx.update_editor(|editor, window, cx| {
1078        let snapshot = editor.snapshot(window, cx);
1079        let highlights = editor
1080            .text_highlights(editor::HighlightKey::PendingInput, cx)
1081            .unwrap()
1082            .1;
1083
1084        assert_eq!(
1085            highlights
1086                .iter()
1087                .map(|highlight| highlight.to_offset(&snapshot.buffer_snapshot()))
1088                .collect::<Vec<_>>(),
1089            vec![MultiBufferOffset(0)..MultiBufferOffset(1)]
1090        )
1091    });
1092    cx.executor().advance_clock(Duration::from_millis(500));
1093    cx.run_until_parked();
1094    cx.assert_state("jˇhello", Mode::Insert);
1095    cx.simulate_keystrokes("k j k");
1096    cx.assert_state("jˇkhello", Mode::Normal);
1097}
1098
1099#[perf]
1100#[gpui::test]
1101async fn test_jk_max_count(cx: &mut gpui::TestAppContext) {
1102    let mut cx = NeovimBackedTestContext::new(cx).await;
1103
1104    cx.set_shared_state("1\nˇ2\n3").await;
1105    cx.simulate_shared_keystrokes("9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 j")
1106        .await;
1107    cx.shared_state().await.assert_eq("1\n2\nˇ3");
1108
1109    let number: String = usize::MAX.to_string().split("").join(" ");
1110    cx.simulate_shared_keystrokes(&format!("{number} k")).await;
1111    cx.shared_state().await.assert_eq("ˇ1\n2\n3");
1112}
1113
1114#[perf]
1115#[gpui::test]
1116async fn test_comma_w(cx: &mut gpui::TestAppContext) {
1117    let mut cx = NeovimBackedTestContext::new(cx).await;
1118
1119    cx.update(|_, cx| {
1120        cx.bind_keys([KeyBinding::new(
1121            ", w",
1122            motion::Down {
1123                display_lines: false,
1124            },
1125            Some("vim_mode == normal"),
1126        )])
1127    });
1128    cx.neovim.exec("map ,w j").await;
1129
1130    cx.set_shared_state("ˇhello hello\nhello hello").await;
1131    cx.simulate_shared_keystrokes("f o ; , w").await;
1132    cx.shared_state()
1133        .await
1134        .assert_eq("hello hello\nhello hellˇo");
1135
1136    cx.set_shared_state("ˇhello hello\nhello hello").await;
1137    cx.simulate_shared_keystrokes("f o ; , i").await;
1138    cx.shared_state()
1139        .await
1140        .assert_eq("hellˇo hello\nhello hello");
1141}
1142
1143#[perf]
1144#[gpui::test]
1145async fn test_completion_menu_scroll_aside(cx: &mut TestAppContext) {
1146    let mut cx = VimTestContext::new_typescript(cx).await;
1147
1148    cx.lsp
1149        .set_request_handler::<lsp::request::Completion, _, _>(move |_, _| async move {
1150            Ok(Some(lsp::CompletionResponse::Array(vec![
1151                lsp::CompletionItem {
1152                    label: "Test Item".to_string(),
1153                    documentation: Some(lsp::Documentation::String(
1154                        "This is some very long documentation content that will be displayed in the aside panel for scrolling.\n".repeat(50)
1155                    )),
1156                    ..Default::default()
1157                },
1158            ])))
1159        });
1160
1161    cx.set_state("variableˇ", Mode::Insert);
1162    cx.simulate_keystroke(".");
1163    cx.executor().run_until_parked();
1164
1165    let mut initial_offset: Pixels = px(0.0);
1166
1167    cx.update_editor(|editor, _, _| {
1168        let binding = editor.context_menu().borrow();
1169        let Some(CodeContextMenu::Completions(menu)) = binding.as_ref() else {
1170            panic!("Should have completions menu open");
1171        };
1172
1173        initial_offset = menu.scroll_handle_aside.offset().y;
1174    });
1175
1176    // The `ctrl-e` shortcut should scroll the completion menu's aside content
1177    // down, so the updated offset should be lower than the initial offset.
1178    cx.simulate_keystroke("ctrl-e");
1179    cx.update_editor(|editor, _, _| {
1180        let binding = editor.context_menu().borrow();
1181        let Some(CodeContextMenu::Completions(menu)) = binding.as_ref() else {
1182            panic!("Should have completions menu open");
1183        };
1184
1185        assert!(menu.scroll_handle_aside.offset().y < initial_offset);
1186    });
1187
1188    // The `ctrl-y` shortcut should do the inverse scrolling as `ctrl-e`, so the
1189    // offset should now be the same as the initial offset.
1190    cx.simulate_keystroke("ctrl-y");
1191    cx.update_editor(|editor, _, _| {
1192        let binding = editor.context_menu().borrow();
1193        let Some(CodeContextMenu::Completions(menu)) = binding.as_ref() else {
1194            panic!("Should have completions menu open");
1195        };
1196
1197        assert_eq!(menu.scroll_handle_aside.offset().y, initial_offset);
1198    });
1199
1200    // The `ctrl-d` shortcut should scroll the completion menu's aside content
1201    // down, so the updated offset should be lower than the initial offset.
1202    cx.simulate_keystroke("ctrl-d");
1203    cx.update_editor(|editor, _, _| {
1204        let binding = editor.context_menu().borrow();
1205        let Some(CodeContextMenu::Completions(menu)) = binding.as_ref() else {
1206            panic!("Should have completions menu open");
1207        };
1208
1209        assert!(menu.scroll_handle_aside.offset().y < initial_offset);
1210    });
1211
1212    // The `ctrl-u` shortcut should do the inverse scrolling as `ctrl-u`, so the
1213    // offset should now be the same as the initial offset.
1214    cx.simulate_keystroke("ctrl-u");
1215    cx.update_editor(|editor, _, _| {
1216        let binding = editor.context_menu().borrow();
1217        let Some(CodeContextMenu::Completions(menu)) = binding.as_ref() else {
1218            panic!("Should have completions menu open");
1219        };
1220
1221        assert_eq!(menu.scroll_handle_aside.offset().y, initial_offset);
1222    });
1223}
1224
1225#[perf]
1226#[gpui::test]
1227async fn test_rename(cx: &mut gpui::TestAppContext) {
1228    let mut cx = VimTestContext::new_typescript(cx).await;
1229
1230    cx.set_state("const beˇfore = 2; console.log(before)", Mode::Normal);
1231    let def_range = cx.lsp_range("const «beforeˇ» = 2; console.log(before)");
1232    let tgt_range = cx.lsp_range("const before = 2; console.log(«beforeˇ»)");
1233    let mut prepare_request = cx.set_request_handler::<lsp::request::PrepareRenameRequest, _, _>(
1234        move |_, _, _| async move { Ok(Some(lsp::PrepareRenameResponse::Range(def_range))) },
1235    );
1236    let mut rename_request =
1237        cx.set_request_handler::<lsp::request::Rename, _, _>(move |url, params, _| async move {
1238            Ok(Some(lsp::WorkspaceEdit {
1239                changes: Some(
1240                    [(
1241                        url.clone(),
1242                        vec![
1243                            lsp::TextEdit::new(def_range, params.new_name.clone()),
1244                            lsp::TextEdit::new(tgt_range, params.new_name),
1245                        ],
1246                    )]
1247                    .into(),
1248                ),
1249                ..Default::default()
1250            }))
1251        });
1252
1253    cx.simulate_keystrokes("c d");
1254    prepare_request.next().await.unwrap();
1255    cx.simulate_input("after");
1256    cx.simulate_keystrokes("enter");
1257    rename_request.next().await.unwrap();
1258    cx.assert_state("const afterˇ = 2; console.log(after)", Mode::Normal)
1259}
1260
1261#[gpui::test]
1262async fn test_go_to_definition(cx: &mut gpui::TestAppContext) {
1263    let mut cx = VimTestContext::new_typescript(cx).await;
1264
1265    cx.set_state("const before = 2; console.log(beforˇe)", Mode::Normal);
1266    let def_range = cx.lsp_range("const «beforeˇ» = 2; console.log(before)");
1267    let mut go_to_request =
1268        cx.set_request_handler::<lsp::request::GotoDefinition, _, _>(move |url, _, _| async move {
1269            Ok(Some(lsp::GotoDefinitionResponse::Scalar(
1270                lsp::Location::new(url.clone(), def_range),
1271            )))
1272        });
1273
1274    cx.simulate_keystrokes("g d");
1275    go_to_request.next().await.unwrap();
1276    cx.run_until_parked();
1277
1278    cx.assert_state("const ˇbefore = 2; console.log(before)", Mode::Normal);
1279}
1280
1281#[perf]
1282#[gpui::test]
1283async fn test_remap(cx: &mut gpui::TestAppContext) {
1284    let mut cx = VimTestContext::new(cx, true).await;
1285
1286    // test moving the cursor
1287    cx.update(|_, cx| {
1288        cx.bind_keys([KeyBinding::new(
1289            "g z",
1290            workspace::SendKeystrokes("l l l l".to_string()),
1291            None,
1292        )])
1293    });
1294    cx.set_state("ˇ123456789", Mode::Normal);
1295    cx.simulate_keystrokes("g z");
1296    cx.assert_state("1234ˇ56789", Mode::Normal);
1297
1298    // test switching modes
1299    cx.update(|_, cx| {
1300        cx.bind_keys([KeyBinding::new(
1301            "g y",
1302            workspace::SendKeystrokes("i f o o escape l".to_string()),
1303            None,
1304        )])
1305    });
1306    cx.set_state("ˇ123456789", Mode::Normal);
1307    cx.simulate_keystrokes("g y");
1308    cx.assert_state("fooˇ123456789", Mode::Normal);
1309
1310    // test recursion
1311    cx.update(|_, cx| {
1312        cx.bind_keys([KeyBinding::new(
1313            "g x",
1314            workspace::SendKeystrokes("g z g y".to_string()),
1315            None,
1316        )])
1317    });
1318    cx.set_state("ˇ123456789", Mode::Normal);
1319    cx.simulate_keystrokes("g x");
1320    cx.assert_state("1234fooˇ56789", Mode::Normal);
1321
1322    // test command
1323    cx.update(|_, cx| {
1324        cx.bind_keys([KeyBinding::new(
1325            "g w",
1326            workspace::SendKeystrokes(": j enter".to_string()),
1327            None,
1328        )])
1329    });
1330    cx.set_state("ˇ1234\n56789", Mode::Normal);
1331    cx.simulate_keystrokes("g w");
1332    cx.assert_state("1234ˇ 56789", Mode::Normal);
1333
1334    // test leaving command
1335    cx.update(|_, cx| {
1336        cx.bind_keys([KeyBinding::new(
1337            "g u",
1338            workspace::SendKeystrokes("g w g z".to_string()),
1339            None,
1340        )])
1341    });
1342    cx.set_state("ˇ1234\n56789", Mode::Normal);
1343    cx.simulate_keystrokes("g u");
1344    cx.assert_state("1234 567ˇ89", Mode::Normal);
1345
1346    // test leaving command
1347    cx.update(|_, cx| {
1348        cx.bind_keys([KeyBinding::new(
1349            "g t",
1350            workspace::SendKeystrokes("i space escape".to_string()),
1351            None,
1352        )])
1353    });
1354    cx.set_state("12ˇ34", Mode::Normal);
1355    cx.simulate_keystrokes("g t");
1356    cx.assert_state("12ˇ 34", Mode::Normal);
1357}
1358
1359#[perf]
1360#[gpui::test]
1361async fn test_undo(cx: &mut gpui::TestAppContext) {
1362    let mut cx = NeovimBackedTestContext::new(cx).await;
1363
1364    cx.set_shared_state("hello quˇoel world").await;
1365    cx.simulate_shared_keystrokes("v i w s c o escape u").await;
1366    cx.shared_state().await.assert_eq("hello ˇquoel world");
1367    cx.simulate_shared_keystrokes("ctrl-r").await;
1368    cx.shared_state().await.assert_eq("hello ˇco world");
1369    cx.simulate_shared_keystrokes("a o right l escape").await;
1370    cx.shared_state().await.assert_eq("hello cooˇl world");
1371    cx.simulate_shared_keystrokes("u").await;
1372    cx.shared_state().await.assert_eq("hello cooˇ world");
1373    cx.simulate_shared_keystrokes("u").await;
1374    cx.shared_state().await.assert_eq("hello cˇo world");
1375    cx.simulate_shared_keystrokes("u").await;
1376    cx.shared_state().await.assert_eq("hello ˇquoel world");
1377
1378    cx.set_shared_state("hello quˇoel world").await;
1379    cx.simulate_shared_keystrokes("v i w ~ u").await;
1380    cx.shared_state().await.assert_eq("hello ˇquoel world");
1381
1382    cx.set_shared_state("\nhello quˇoel world\n").await;
1383    cx.simulate_shared_keystrokes("shift-v s c escape u").await;
1384    cx.shared_state().await.assert_eq("\nˇhello quoel world\n");
1385
1386    cx.set_shared_state(indoc! {"
1387        ˇ1
1388        2
1389        3"})
1390        .await;
1391
1392    cx.simulate_shared_keystrokes("ctrl-v shift-g ctrl-a").await;
1393    cx.shared_state().await.assert_eq(indoc! {"
1394        ˇ2
1395        3
1396        4"});
1397
1398    cx.simulate_shared_keystrokes("u").await;
1399    cx.shared_state().await.assert_eq(indoc! {"
1400        ˇ1
1401        2
1402        3"});
1403}
1404
1405#[perf]
1406#[gpui::test]
1407async fn test_mouse_selection(cx: &mut TestAppContext) {
1408    let mut cx = VimTestContext::new(cx, true).await;
1409
1410    cx.set_state("ˇone two three", Mode::Normal);
1411
1412    let start_point = cx.pixel_position("one twˇo three");
1413    let end_point = cx.pixel_position("one ˇtwo three");
1414
1415    cx.simulate_mouse_down(start_point, MouseButton::Left, Modifiers::none());
1416    cx.simulate_mouse_move(end_point, MouseButton::Left, Modifiers::none());
1417    cx.simulate_mouse_up(end_point, MouseButton::Left, Modifiers::none());
1418
1419    cx.assert_state("one «ˇtwo» three", Mode::Visual)
1420}
1421
1422#[gpui::test]
1423async fn test_mouse_drag_across_anchor_does_not_drift(cx: &mut TestAppContext) {
1424    let mut cx = VimTestContext::new(cx, true).await;
1425
1426    cx.set_state("ˇone two three four", Mode::Normal);
1427
1428    let click_pos = cx.pixel_position("one ˇtwo three four");
1429    let drag_left = cx.pixel_position("ˇone two three four");
1430    let anchor_pos = cx.pixel_position("one tˇwo three four");
1431
1432    cx.simulate_mouse_down(click_pos, MouseButton::Left, Modifiers::none());
1433    cx.run_until_parked();
1434
1435    cx.simulate_mouse_move(drag_left, MouseButton::Left, Modifiers::none());
1436    cx.run_until_parked();
1437    cx.assert_state("«ˇone t»wo three four", Mode::Visual);
1438
1439    cx.simulate_mouse_move(anchor_pos, MouseButton::Left, Modifiers::none());
1440    cx.run_until_parked();
1441
1442    cx.simulate_mouse_move(drag_left, MouseButton::Left, Modifiers::none());
1443    cx.run_until_parked();
1444    cx.assert_state("«ˇone t»wo three four", Mode::Visual);
1445
1446    cx.simulate_mouse_move(anchor_pos, MouseButton::Left, Modifiers::none());
1447    cx.run_until_parked();
1448    cx.simulate_mouse_move(drag_left, MouseButton::Left, Modifiers::none());
1449    cx.run_until_parked();
1450    cx.assert_state("«ˇone t»wo three four", Mode::Visual);
1451
1452    cx.simulate_mouse_up(drag_left, MouseButton::Left, Modifiers::none());
1453}
1454
1455#[perf]
1456#[gpui::test]
1457async fn test_lowercase_marks(cx: &mut TestAppContext) {
1458    let mut cx = NeovimBackedTestContext::new(cx).await;
1459
1460    cx.set_shared_state("line one\nline ˇtwo\nline three").await;
1461    cx.simulate_shared_keystrokes("m a l ' a").await;
1462    cx.shared_state()
1463        .await
1464        .assert_eq("line one\nˇline two\nline three");
1465    cx.simulate_shared_keystrokes("` a").await;
1466    cx.shared_state()
1467        .await
1468        .assert_eq("line one\nline ˇtwo\nline three");
1469
1470    cx.simulate_shared_keystrokes("^ d ` a").await;
1471    cx.shared_state()
1472        .await
1473        .assert_eq("line one\nˇtwo\nline three");
1474}
1475
1476#[perf]
1477#[gpui::test]
1478async fn test_lt_gt_marks(cx: &mut TestAppContext) {
1479    let mut cx = NeovimBackedTestContext::new(cx).await;
1480
1481    cx.set_shared_state(indoc!(
1482        "
1483        Line one
1484        Line two
1485        Line ˇthree
1486        Line four
1487        Line five
1488    "
1489    ))
1490    .await;
1491
1492    cx.simulate_shared_keystrokes("v j escape k k").await;
1493
1494    cx.simulate_shared_keystrokes("' <").await;
1495    cx.shared_state().await.assert_eq(indoc! {"
1496        Line one
1497        Line two
1498        ˇLine three
1499        Line four
1500        Line five
1501    "});
1502
1503    cx.simulate_shared_keystrokes("` <").await;
1504    cx.shared_state().await.assert_eq(indoc! {"
1505        Line one
1506        Line two
1507        Line ˇthree
1508        Line four
1509        Line five
1510    "});
1511
1512    cx.simulate_shared_keystrokes("' >").await;
1513    cx.shared_state().await.assert_eq(indoc! {"
1514        Line one
1515        Line two
1516        Line three
1517        ˇLine four
1518        Line five
1519    "
1520    });
1521
1522    cx.simulate_shared_keystrokes("` >").await;
1523    cx.shared_state().await.assert_eq(indoc! {"
1524        Line one
1525        Line two
1526        Line three
1527        Line ˇfour
1528        Line five
1529    "
1530    });
1531
1532    cx.simulate_shared_keystrokes("v i w o escape").await;
1533    cx.simulate_shared_keystrokes("` >").await;
1534    cx.shared_state().await.assert_eq(indoc! {"
1535        Line one
1536        Line two
1537        Line three
1538        Line fouˇr
1539        Line five
1540    "
1541    });
1542    cx.simulate_shared_keystrokes("` <").await;
1543    cx.shared_state().await.assert_eq(indoc! {"
1544        Line one
1545        Line two
1546        Line three
1547        Line ˇfour
1548        Line five
1549    "
1550    });
1551}
1552
1553#[perf]
1554#[gpui::test]
1555async fn test_caret_mark(cx: &mut TestAppContext) {
1556    let mut cx = NeovimBackedTestContext::new(cx).await;
1557
1558    cx.set_shared_state(indoc!(
1559        "
1560        Line one
1561        Line two
1562        Line three
1563        ˇLine four
1564        Line five
1565    "
1566    ))
1567    .await;
1568
1569    cx.simulate_shared_keystrokes("c w shift-s t r a i g h t space t h i n g escape j j")
1570        .await;
1571
1572    cx.simulate_shared_keystrokes("' ^").await;
1573    cx.shared_state().await.assert_eq(indoc! {"
1574        Line one
1575        Line two
1576        Line three
1577        ˇStraight thing four
1578        Line five
1579    "
1580    });
1581
1582    cx.simulate_shared_keystrokes("` ^").await;
1583    cx.shared_state().await.assert_eq(indoc! {"
1584        Line one
1585        Line two
1586        Line three
1587        Straight thingˇ four
1588        Line five
1589    "
1590    });
1591
1592    cx.simulate_shared_keystrokes("k a ! escape k g i ?").await;
1593    cx.shared_state().await.assert_eq(indoc! {"
1594        Line one
1595        Line two
1596        Line three!?ˇ
1597        Straight thing four
1598        Line five
1599    "
1600    });
1601}
1602
1603#[cfg(target_os = "macos")]
1604#[perf]
1605#[gpui::test]
1606async fn test_dw_eol(cx: &mut gpui::TestAppContext) {
1607    let mut cx = NeovimBackedTestContext::new(cx).await;
1608
1609    cx.set_shared_wrap(12).await;
1610    cx.set_shared_state("twelve ˇchar twelve char\ntwelve char")
1611        .await;
1612    cx.simulate_shared_keystrokes("d w").await;
1613    cx.shared_state()
1614        .await
1615        .assert_eq("twelve ˇtwelve char\ntwelve char");
1616}
1617
1618#[perf]
1619#[gpui::test]
1620async fn test_toggle_comments(cx: &mut gpui::TestAppContext) {
1621    let mut cx = VimTestContext::new(cx, true).await;
1622
1623    let language = std::sync::Arc::new(language::Language::new(
1624        language::LanguageConfig {
1625            line_comments: vec!["// ".into(), "//! ".into(), "/// ".into()],
1626            ..Default::default()
1627        },
1628        Some(language::tree_sitter_rust::LANGUAGE.into()),
1629    ));
1630    cx.update_buffer(|buffer, cx| buffer.set_language(Some(language), cx));
1631
1632    // works in normal model
1633    cx.set_state(
1634        indoc! {"
1635      ˇone
1636      two
1637      three
1638      "},
1639        Mode::Normal,
1640    );
1641    cx.simulate_keystrokes("g c c");
1642    cx.assert_state(
1643        indoc! {"
1644          // ˇone
1645          two
1646          three
1647          "},
1648        Mode::Normal,
1649    );
1650
1651    // works in visual mode
1652    cx.simulate_keystrokes("v j g c");
1653    cx.assert_state(
1654        indoc! {"
1655          // // ˇone
1656          // two
1657          three
1658          "},
1659        Mode::Normal,
1660    );
1661
1662    // works in visual line mode
1663    cx.simulate_keystrokes("shift-v j g c");
1664    cx.assert_state(
1665        indoc! {"
1666          // ˇone
1667          two
1668          three
1669          "},
1670        Mode::Normal,
1671    );
1672
1673    // works with count
1674    cx.simulate_keystrokes("g c 2 j");
1675    cx.assert_state(
1676        indoc! {"
1677            // // ˇone
1678            // two
1679            // three
1680            "},
1681        Mode::Normal,
1682    );
1683
1684    // works with motion object
1685    cx.simulate_keystrokes("shift-g");
1686    cx.simulate_keystrokes("g c g g");
1687    cx.assert_state(
1688        indoc! {"
1689            // one
1690            two
1691            three
1692            ˇ"},
1693        Mode::Normal,
1694    );
1695}
1696
1697#[perf]
1698#[gpui::test]
1699async fn test_find_multibyte(cx: &mut gpui::TestAppContext) {
1700    let mut cx = NeovimBackedTestContext::new(cx).await;
1701
1702    cx.set_shared_state(r#"<label for="guests">ˇPočet hostů</label>"#)
1703        .await;
1704
1705    cx.simulate_shared_keystrokes("c t < o escape").await;
1706    cx.shared_state()
1707        .await
1708        .assert_eq(r#"<label for="guests">ˇo</label>"#);
1709}
1710
1711#[perf]
1712#[gpui::test]
1713async fn test_sneak(cx: &mut gpui::TestAppContext) {
1714    let mut cx = VimTestContext::new(cx, true).await;
1715
1716    cx.update(|_window, cx| {
1717        cx.bind_keys([
1718            KeyBinding::new(
1719                "s",
1720                PushSneak { first_char: None },
1721                Some("vim_mode == normal"),
1722            ),
1723            KeyBinding::new(
1724                "shift-s",
1725                PushSneakBackward { first_char: None },
1726                Some("vim_mode == normal"),
1727            ),
1728            KeyBinding::new(
1729                "shift-s",
1730                PushSneakBackward { first_char: None },
1731                Some("vim_mode == visual"),
1732            ),
1733        ])
1734    });
1735
1736    // Sneak forwards multibyte & multiline
1737    cx.set_state(
1738        indoc! {
1739            r#"<labelˇ for="guests">
1740                    Počet hostů
1741                </label>"#
1742        },
1743        Mode::Normal,
1744    );
1745    cx.simulate_keystrokes("s t ů");
1746    cx.assert_state(
1747        indoc! {
1748            r#"<label for="guests">
1749                Počet hosˇtů
1750            </label>"#
1751        },
1752        Mode::Normal,
1753    );
1754
1755    // Visual sneak backwards multibyte & multiline
1756    cx.simulate_keystrokes("v S < l");
1757    cx.assert_state(
1758        indoc! {
1759            r#"«ˇ<label for="guests">
1760                Počet host»ů
1761            </label>"#
1762        },
1763        Mode::Visual,
1764    );
1765
1766    // Sneak backwards repeated
1767    cx.set_state(r#"11 12 13 ˇ14"#, Mode::Normal);
1768    cx.simulate_keystrokes("S space 1");
1769    cx.assert_state(r#"11 12ˇ 13 14"#, Mode::Normal);
1770    cx.simulate_keystrokes(";");
1771    cx.assert_state(r#"11ˇ 12 13 14"#, Mode::Normal);
1772}
1773
1774#[perf]
1775#[gpui::test]
1776async fn test_plus_minus(cx: &mut gpui::TestAppContext) {
1777    let mut cx = NeovimBackedTestContext::new(cx).await;
1778
1779    cx.set_shared_state(indoc! {
1780        "one
1781           two
1782        thrˇee
1783    "})
1784        .await;
1785
1786    cx.simulate_shared_keystrokes("-").await;
1787    cx.shared_state().await.assert_matches();
1788    cx.simulate_shared_keystrokes("-").await;
1789    cx.shared_state().await.assert_matches();
1790    cx.simulate_shared_keystrokes("+").await;
1791    cx.shared_state().await.assert_matches();
1792}
1793
1794#[perf]
1795#[gpui::test]
1796async fn test_command_alias(cx: &mut gpui::TestAppContext) {
1797    let mut cx = VimTestContext::new(cx, true).await;
1798    cx.update_global(|store: &mut SettingsStore, cx| {
1799        store.update_user_settings(cx, |s| {
1800            let mut aliases = HashMap::default();
1801            aliases.insert("Q".to_string(), "upper".to_string());
1802            s.workspace.command_aliases = aliases
1803        });
1804    });
1805
1806    cx.set_state("ˇhello world", Mode::Normal);
1807    cx.simulate_keystrokes(": Q");
1808    cx.set_state("ˇHello world", Mode::Normal);
1809}
1810
1811#[perf]
1812#[gpui::test]
1813async fn test_remap_adjacent_dog_cat(cx: &mut gpui::TestAppContext) {
1814    let mut cx = NeovimBackedTestContext::new(cx).await;
1815    cx.update(|_, cx| {
1816        cx.bind_keys([
1817            KeyBinding::new(
1818                "d o g",
1819                workspace::SendKeystrokes("🐶".to_string()),
1820                Some("vim_mode == insert"),
1821            ),
1822            KeyBinding::new(
1823                "c a t",
1824                workspace::SendKeystrokes("🐱".to_string()),
1825                Some("vim_mode == insert"),
1826            ),
1827        ])
1828    });
1829    cx.neovim.exec("imap dog 🐶").await;
1830    cx.neovim.exec("imap cat 🐱").await;
1831
1832    cx.set_shared_state("ˇ").await;
1833    cx.simulate_shared_keystrokes("i d o g").await;
1834    cx.shared_state().await.assert_eq("🐶ˇ");
1835
1836    cx.set_shared_state("ˇ").await;
1837    cx.simulate_shared_keystrokes("i d o d o g").await;
1838    cx.shared_state().await.assert_eq("do🐶ˇ");
1839
1840    cx.set_shared_state("ˇ").await;
1841    cx.simulate_shared_keystrokes("i d o c a t").await;
1842    cx.shared_state().await.assert_eq("do🐱ˇ");
1843}
1844
1845#[perf]
1846#[gpui::test]
1847async fn test_remap_nested_pineapple(cx: &mut gpui::TestAppContext) {
1848    let mut cx = NeovimBackedTestContext::new(cx).await;
1849    cx.update(|_, cx| {
1850        cx.bind_keys([
1851            KeyBinding::new(
1852                "p i n",
1853                workspace::SendKeystrokes("📌".to_string()),
1854                Some("vim_mode == insert"),
1855            ),
1856            KeyBinding::new(
1857                "p i n e",
1858                workspace::SendKeystrokes("🌲".to_string()),
1859                Some("vim_mode == insert"),
1860            ),
1861            KeyBinding::new(
1862                "p i n e a p p l e",
1863                workspace::SendKeystrokes("🍍".to_string()),
1864                Some("vim_mode == insert"),
1865            ),
1866        ])
1867    });
1868    cx.neovim.exec("imap pin 📌").await;
1869    cx.neovim.exec("imap pine 🌲").await;
1870    cx.neovim.exec("imap pineapple 🍍").await;
1871
1872    cx.set_shared_state("ˇ").await;
1873    cx.simulate_shared_keystrokes("i p i n").await;
1874    cx.executor().advance_clock(Duration::from_millis(1000));
1875    cx.run_until_parked();
1876    cx.shared_state().await.assert_eq("📌ˇ");
1877
1878    cx.set_shared_state("ˇ").await;
1879    cx.simulate_shared_keystrokes("i p i n e").await;
1880    cx.executor().advance_clock(Duration::from_millis(1000));
1881    cx.run_until_parked();
1882    cx.shared_state().await.assert_eq("🌲ˇ");
1883
1884    cx.set_shared_state("ˇ").await;
1885    cx.simulate_shared_keystrokes("i p i n e a p p l e").await;
1886    cx.shared_state().await.assert_eq("🍍ˇ");
1887}
1888
1889#[perf]
1890#[gpui::test]
1891async fn test_remap_recursion(cx: &mut gpui::TestAppContext) {
1892    let mut cx = NeovimBackedTestContext::new(cx).await;
1893    cx.update(|_, cx| {
1894        cx.bind_keys([KeyBinding::new(
1895            "x",
1896            workspace::SendKeystrokes("\" _ x".to_string()),
1897            Some("VimControl"),
1898        )]);
1899        cx.bind_keys([KeyBinding::new(
1900            "y",
1901            workspace::SendKeystrokes("2 x".to_string()),
1902            Some("VimControl"),
1903        )])
1904    });
1905    cx.neovim.exec("noremap x \"_x").await;
1906    cx.neovim.exec("map y 2x").await;
1907
1908    cx.set_shared_state("ˇhello").await;
1909    cx.simulate_shared_keystrokes("d l").await;
1910    cx.shared_clipboard().await.assert_eq("h");
1911    cx.simulate_shared_keystrokes("y").await;
1912    cx.shared_clipboard().await.assert_eq("h");
1913    cx.shared_state().await.assert_eq("ˇlo");
1914}
1915
1916#[perf]
1917#[gpui::test]
1918async fn test_escape_while_waiting(cx: &mut gpui::TestAppContext) {
1919    let mut cx = NeovimBackedTestContext::new(cx).await;
1920    cx.set_shared_state("ˇhi").await;
1921    cx.simulate_shared_keystrokes("\" + escape x").await;
1922    cx.shared_state().await.assert_eq("ˇi");
1923}
1924
1925#[perf]
1926#[gpui::test]
1927async fn test_ctrl_w_override(cx: &mut gpui::TestAppContext) {
1928    let mut cx = NeovimBackedTestContext::new(cx).await;
1929    cx.update(|_, cx| {
1930        cx.bind_keys([KeyBinding::new("ctrl-w", DeleteLine, None)]);
1931    });
1932    cx.neovim.exec("map <c-w> D").await;
1933    cx.set_shared_state("ˇhi").await;
1934    cx.simulate_shared_keystrokes("ctrl-w").await;
1935    cx.shared_state().await.assert_eq("ˇ");
1936}
1937
1938#[perf]
1939#[gpui::test]
1940async fn test_visual_indent_count(cx: &mut gpui::TestAppContext) {
1941    let mut cx = VimTestContext::new(cx, true).await;
1942    cx.set_state("ˇhi", Mode::Normal);
1943    cx.simulate_keystrokes("shift-v 3 >");
1944    cx.assert_state("            ˇhi", Mode::Normal);
1945    cx.simulate_keystrokes("shift-v 2 <");
1946    cx.assert_state("    ˇhi", Mode::Normal);
1947}
1948
1949#[perf]
1950#[gpui::test]
1951async fn test_record_replay_recursion(cx: &mut gpui::TestAppContext) {
1952    let mut cx = NeovimBackedTestContext::new(cx).await;
1953
1954    cx.set_shared_state("ˇhello world").await;
1955    cx.simulate_shared_keystrokes(">").await;
1956    cx.simulate_shared_keystrokes(".").await;
1957    cx.simulate_shared_keystrokes(".").await;
1958    cx.simulate_shared_keystrokes(".").await;
1959    cx.shared_state().await.assert_eq("ˇhello world");
1960}
1961
1962#[perf]
1963#[gpui::test]
1964async fn test_blackhole_register(cx: &mut gpui::TestAppContext) {
1965    let mut cx = NeovimBackedTestContext::new(cx).await;
1966
1967    cx.set_shared_state("ˇhello world").await;
1968    cx.simulate_shared_keystrokes("d i w \" _ d a w").await;
1969    cx.simulate_shared_keystrokes("p").await;
1970    cx.shared_state().await.assert_eq("hellˇo");
1971}
1972
1973#[perf]
1974#[gpui::test]
1975async fn test_sentence_backwards(cx: &mut gpui::TestAppContext) {
1976    let mut cx = NeovimBackedTestContext::new(cx).await;
1977
1978    cx.set_shared_state("one\n\ntwo\nthree\nˇ\nfour").await;
1979    cx.simulate_shared_keystrokes("(").await;
1980    cx.shared_state()
1981        .await
1982        .assert_eq("one\n\nˇtwo\nthree\n\nfour");
1983
1984    cx.set_shared_state("hello.\n\n\nworˇld.").await;
1985    cx.simulate_shared_keystrokes("(").await;
1986    cx.shared_state().await.assert_eq("hello.\n\n\nˇworld.");
1987    cx.simulate_shared_keystrokes("(").await;
1988    cx.shared_state().await.assert_eq("hello.\n\nˇ\nworld.");
1989    cx.simulate_shared_keystrokes("(").await;
1990    cx.shared_state().await.assert_eq("ˇhello.\n\n\nworld.");
1991
1992    cx.set_shared_state("hello. worlˇd.").await;
1993    cx.simulate_shared_keystrokes("(").await;
1994    cx.shared_state().await.assert_eq("hello. ˇworld.");
1995    cx.simulate_shared_keystrokes("(").await;
1996    cx.shared_state().await.assert_eq("ˇhello. world.");
1997
1998    cx.set_shared_state(". helˇlo.").await;
1999    cx.simulate_shared_keystrokes("(").await;
2000    cx.shared_state().await.assert_eq(". ˇhello.");
2001    cx.simulate_shared_keystrokes("(").await;
2002    cx.shared_state().await.assert_eq(". ˇhello.");
2003
2004    cx.set_shared_state(indoc! {
2005        "{
2006            hello_world();
2007        ˇ}"
2008    })
2009    .await;
2010    cx.simulate_shared_keystrokes("(").await;
2011    cx.shared_state().await.assert_eq(indoc! {
2012        "ˇ{
2013            hello_world();
2014        }"
2015    });
2016
2017    cx.set_shared_state(indoc! {
2018        "Hello! World..?
2019
2020        \tHello! World... ˇ"
2021    })
2022    .await;
2023    cx.simulate_shared_keystrokes("(").await;
2024    cx.shared_state().await.assert_eq(indoc! {
2025        "Hello! World..?
2026
2027        \tHello! ˇWorld... "
2028    });
2029    cx.simulate_shared_keystrokes("(").await;
2030    cx.shared_state().await.assert_eq(indoc! {
2031        "Hello! World..?
2032
2033        \tˇHello! World... "
2034    });
2035    cx.simulate_shared_keystrokes("(").await;
2036    cx.shared_state().await.assert_eq(indoc! {
2037        "Hello! World..?
2038        ˇ
2039        \tHello! World... "
2040    });
2041    cx.simulate_shared_keystrokes("(").await;
2042    cx.shared_state().await.assert_eq(indoc! {
2043        "Hello! ˇWorld..?
2044
2045        \tHello! World... "
2046    });
2047}
2048
2049#[perf]
2050#[gpui::test]
2051async fn test_sentence_forwards(cx: &mut gpui::TestAppContext) {
2052    let mut cx = NeovimBackedTestContext::new(cx).await;
2053
2054    cx.set_shared_state("helˇlo.\n\n\nworld.").await;
2055    cx.simulate_shared_keystrokes(")").await;
2056    cx.shared_state().await.assert_eq("hello.\nˇ\n\nworld.");
2057    cx.simulate_shared_keystrokes(")").await;
2058    cx.shared_state().await.assert_eq("hello.\n\n\nˇworld.");
2059    cx.simulate_shared_keystrokes(")").await;
2060    cx.shared_state().await.assert_eq("hello.\n\n\nworldˇ.");
2061
2062    cx.set_shared_state("helˇlo.\n\n\nworld.").await;
2063}
2064
2065#[perf]
2066#[gpui::test]
2067async fn test_ctrl_o_visual(cx: &mut gpui::TestAppContext) {
2068    let mut cx = NeovimBackedTestContext::new(cx).await;
2069
2070    cx.set_shared_state("helloˇ world.").await;
2071    cx.simulate_shared_keystrokes("i ctrl-o v b r l").await;
2072    cx.shared_state().await.assert_eq("ˇllllllworld.");
2073    cx.simulate_shared_keystrokes("ctrl-o v f w d").await;
2074    cx.shared_state().await.assert_eq("ˇorld.");
2075}
2076
2077#[perf]
2078#[gpui::test]
2079async fn test_ctrl_o_position(cx: &mut gpui::TestAppContext) {
2080    let mut cx = NeovimBackedTestContext::new(cx).await;
2081
2082    cx.set_shared_state("helˇlo world.").await;
2083    cx.simulate_shared_keystrokes("i ctrl-o d i w").await;
2084    cx.shared_state().await.assert_eq("ˇ world.");
2085    cx.simulate_shared_keystrokes("ctrl-o p").await;
2086    cx.shared_state().await.assert_eq(" helloˇworld.");
2087}
2088
2089#[perf]
2090#[gpui::test]
2091async fn test_ctrl_o_dot(cx: &mut gpui::TestAppContext) {
2092    let mut cx = NeovimBackedTestContext::new(cx).await;
2093
2094    cx.set_shared_state("heˇllo world.").await;
2095    cx.simulate_shared_keystrokes("x i ctrl-o .").await;
2096    cx.shared_state().await.assert_eq("heˇo world.");
2097    cx.simulate_shared_keystrokes("l l escape .").await;
2098    cx.shared_state().await.assert_eq("hellˇllo world.");
2099}
2100
2101#[perf(iterations = 1)]
2102#[gpui::test]
2103async fn test_folded_multibuffer_excerpts(cx: &mut gpui::TestAppContext) {
2104    VimTestContext::init(cx);
2105    cx.update(|cx| {
2106        VimTestContext::init_keybindings(true, cx);
2107    });
2108    let (editor, cx) = cx.add_window_view(|window, cx| {
2109        let multi_buffer = MultiBuffer::build_multi(
2110            [
2111                ("111\n222\n333\n444\n", vec![Point::row_range(0..2)]),
2112                ("aaa\nbbb\nccc\nddd\n", vec![Point::row_range(0..2)]),
2113                ("AAA\nBBB\nCCC\nDDD\n", vec![Point::row_range(0..2)]),
2114                ("one\ntwo\nthr\nfou\n", vec![Point::row_range(0..2)]),
2115            ],
2116            cx,
2117        );
2118        let mut editor = Editor::new(EditorMode::full(), multi_buffer.clone(), None, window, cx);
2119
2120        let buffer_ids = multi_buffer.read(cx).excerpt_buffer_ids();
2121        // fold all but the second buffer, so that we test navigating between two
2122        // adjacent folded buffers, as well as folded buffers at the start and
2123        // end the multibuffer
2124        editor.fold_buffer(buffer_ids[0], cx);
2125        editor.fold_buffer(buffer_ids[2], cx);
2126        editor.fold_buffer(buffer_ids[3], cx);
2127
2128        editor
2129    });
2130    let mut cx = EditorTestContext::for_editor_in(editor.clone(), cx).await;
2131
2132    cx.assert_excerpts_with_selections(indoc! {"
2133        [EXCERPT]
2134        ˇ[FOLDED]
2135        [EXCERPT]
2136        aaa
2137        bbb
2138        [EXCERPT]
2139        [FOLDED]
2140        [EXCERPT]
2141        [FOLDED]
2142        "
2143    });
2144    cx.simulate_keystroke("j");
2145    cx.assert_excerpts_with_selections(indoc! {"
2146        [EXCERPT]
2147        [FOLDED]
2148        [EXCERPT]
2149        ˇaaa
2150        bbb
2151        [EXCERPT]
2152        [FOLDED]
2153        [EXCERPT]
2154        [FOLDED]
2155        "
2156    });
2157    cx.simulate_keystroke("j");
2158    cx.simulate_keystroke("j");
2159    cx.assert_excerpts_with_selections(indoc! {"
2160        [EXCERPT]
2161        [FOLDED]
2162        [EXCERPT]
2163        aaa
2164        bbb
2165        ˇ[EXCERPT]
2166        [FOLDED]
2167        [EXCERPT]
2168        [FOLDED]
2169        "
2170    });
2171    cx.simulate_keystroke("j");
2172    cx.assert_excerpts_with_selections(indoc! {"
2173        [EXCERPT]
2174        [FOLDED]
2175        [EXCERPT]
2176        aaa
2177        bbb
2178        [EXCERPT]
2179        ˇ[FOLDED]
2180        [EXCERPT]
2181        [FOLDED]
2182        "
2183    });
2184    cx.simulate_keystroke("j");
2185    cx.assert_excerpts_with_selections(indoc! {"
2186        [EXCERPT]
2187        [FOLDED]
2188        [EXCERPT]
2189        aaa
2190        bbb
2191        [EXCERPT]
2192        [FOLDED]
2193        [EXCERPT]
2194        ˇ[FOLDED]
2195        "
2196    });
2197    cx.simulate_keystroke("k");
2198    cx.assert_excerpts_with_selections(indoc! {"
2199        [EXCERPT]
2200        [FOLDED]
2201        [EXCERPT]
2202        aaa
2203        bbb
2204        [EXCERPT]
2205        ˇ[FOLDED]
2206        [EXCERPT]
2207        [FOLDED]
2208        "
2209    });
2210    cx.simulate_keystroke("k");
2211    cx.simulate_keystroke("k");
2212    cx.simulate_keystroke("k");
2213    cx.assert_excerpts_with_selections(indoc! {"
2214        [EXCERPT]
2215        [FOLDED]
2216        [EXCERPT]
2217        ˇaaa
2218        bbb
2219        [EXCERPT]
2220        [FOLDED]
2221        [EXCERPT]
2222        [FOLDED]
2223        "
2224    });
2225    cx.simulate_keystroke("k");
2226    cx.assert_excerpts_with_selections(indoc! {"
2227        [EXCERPT]
2228        ˇ[FOLDED]
2229        [EXCERPT]
2230        aaa
2231        bbb
2232        [EXCERPT]
2233        [FOLDED]
2234        [EXCERPT]
2235        [FOLDED]
2236        "
2237    });
2238    cx.simulate_keystroke("shift-g");
2239    cx.assert_excerpts_with_selections(indoc! {"
2240        [EXCERPT]
2241        [FOLDED]
2242        [EXCERPT]
2243        aaa
2244        bbb
2245        [EXCERPT]
2246        [FOLDED]
2247        [EXCERPT]
2248        ˇ[FOLDED]
2249        "
2250    });
2251    cx.simulate_keystrokes("g g");
2252    cx.assert_excerpts_with_selections(indoc! {"
2253        [EXCERPT]
2254        ˇ[FOLDED]
2255        [EXCERPT]
2256        aaa
2257        bbb
2258        [EXCERPT]
2259        [FOLDED]
2260        [EXCERPT]
2261        [FOLDED]
2262        "
2263    });
2264    cx.update_editor(|editor, _, cx| {
2265        let buffer_ids = editor.buffer().read(cx).excerpt_buffer_ids();
2266        editor.fold_buffer(buffer_ids[1], cx);
2267    });
2268
2269    cx.assert_excerpts_with_selections(indoc! {"
2270        [EXCERPT]
2271        ˇ[FOLDED]
2272        [EXCERPT]
2273        [FOLDED]
2274        [EXCERPT]
2275        [FOLDED]
2276        [EXCERPT]
2277        [FOLDED]
2278        "
2279    });
2280    cx.simulate_keystrokes("2 j");
2281    cx.assert_excerpts_with_selections(indoc! {"
2282        [EXCERPT]
2283        [FOLDED]
2284        [EXCERPT]
2285        [FOLDED]
2286        [EXCERPT]
2287        ˇ[FOLDED]
2288        [EXCERPT]
2289        [FOLDED]
2290        "
2291    });
2292}
2293
2294#[perf]
2295#[gpui::test]
2296async fn test_delete_paragraph_motion(cx: &mut gpui::TestAppContext) {
2297    let mut cx = NeovimBackedTestContext::new(cx).await;
2298    cx.set_shared_state(indoc! {
2299        "ˇhello world.
2300
2301        hello world.
2302        "
2303    })
2304    .await;
2305    cx.simulate_shared_keystrokes("y }").await;
2306    cx.shared_clipboard().await.assert_eq("hello world.\n");
2307    cx.simulate_shared_keystrokes("d }").await;
2308    cx.shared_state().await.assert_eq("ˇ\nhello world.\n");
2309    cx.shared_clipboard().await.assert_eq("hello world.\n");
2310
2311    cx.set_shared_state(indoc! {
2312        "helˇlo world.
2313
2314            hello world.
2315            "
2316    })
2317    .await;
2318    cx.simulate_shared_keystrokes("y }").await;
2319    cx.shared_clipboard().await.assert_eq("lo world.");
2320    cx.simulate_shared_keystrokes("d }").await;
2321    cx.shared_state().await.assert_eq("heˇl\n\nhello world.\n");
2322    cx.shared_clipboard().await.assert_eq("lo world.");
2323}
2324
2325#[perf]
2326#[gpui::test]
2327async fn test_delete_unmatched_brace(cx: &mut gpui::TestAppContext) {
2328    let mut cx = NeovimBackedTestContext::new(cx).await;
2329    cx.set_shared_state(indoc! {
2330        "fn o(wow: i32) {
2331          othˇ(wow)
2332          oth(wow)
2333        }
2334        "
2335    })
2336    .await;
2337    cx.simulate_shared_keystrokes("d ] }").await;
2338    cx.shared_state().await.assert_eq(indoc! {
2339        "fn o(wow: i32) {
2340          otˇh
2341        }
2342        "
2343    });
2344    cx.shared_clipboard().await.assert_eq("(wow)\n  oth(wow)");
2345    cx.set_shared_state(indoc! {
2346        "fn o(wow: i32) {
2347          ˇoth(wow)
2348          oth(wow)
2349        }
2350        "
2351    })
2352    .await;
2353    cx.simulate_shared_keystrokes("d ] }").await;
2354    cx.shared_state().await.assert_eq(indoc! {
2355        "fn o(wow: i32) {
2356         ˇ}
2357        "
2358    });
2359    cx.shared_clipboard()
2360        .await
2361        .assert_eq("  oth(wow)\n  oth(wow)\n");
2362}
2363
2364#[perf]
2365#[gpui::test]
2366async fn test_paragraph_multi_delete(cx: &mut gpui::TestAppContext) {
2367    let mut cx = NeovimBackedTestContext::new(cx).await;
2368    cx.set_shared_state(indoc! {
2369        "
2370        Emacs is
2371        ˇa great
2372
2373        operating system
2374
2375        all it lacks
2376        is a
2377
2378        decent text editor
2379        "
2380    })
2381    .await;
2382
2383    cx.simulate_shared_keystrokes("2 d a p").await;
2384    cx.shared_state().await.assert_eq(indoc! {
2385        "
2386        ˇall it lacks
2387        is a
2388
2389        decent text editor
2390        "
2391    });
2392
2393    cx.simulate_shared_keystrokes("d a p").await;
2394    cx.shared_clipboard()
2395        .await
2396        .assert_eq("all it lacks\nis a\n\n");
2397
2398    //reset to initial state
2399    cx.simulate_shared_keystrokes("2 u").await;
2400
2401    cx.simulate_shared_keystrokes("4 d a p").await;
2402    cx.shared_state().await.assert_eq(indoc! {"ˇ"});
2403}
2404
2405#[perf]
2406#[gpui::test]
2407async fn test_yank_paragraph_with_paste(cx: &mut gpui::TestAppContext) {
2408    let mut cx = NeovimBackedTestContext::new(cx).await;
2409    cx.set_shared_state(indoc! {
2410        "
2411        first paragraph
2412        ˇstill first
2413
2414        second paragraph
2415        still second
2416
2417        third paragraph
2418        "
2419    })
2420    .await;
2421
2422    cx.simulate_shared_keystrokes("y a p").await;
2423    cx.shared_clipboard()
2424        .await
2425        .assert_eq("first paragraph\nstill first\n\n");
2426
2427    cx.simulate_shared_keystrokes("j j p").await;
2428    cx.shared_state().await.assert_eq(indoc! {
2429        "
2430        first paragraph
2431        still first
2432
2433        ˇfirst paragraph
2434        still first
2435
2436        second paragraph
2437        still second
2438
2439        third paragraph
2440        "
2441    });
2442}
2443
2444#[perf]
2445#[gpui::test]
2446async fn test_change_paragraph(cx: &mut gpui::TestAppContext) {
2447    let mut cx = NeovimBackedTestContext::new(cx).await;
2448    cx.set_shared_state(indoc! {
2449        "
2450        first paragraph
2451        ˇstill first
2452
2453        second paragraph
2454        still second
2455
2456        third paragraph
2457        "
2458    })
2459    .await;
2460
2461    cx.simulate_shared_keystrokes("c a p").await;
2462    cx.shared_clipboard()
2463        .await
2464        .assert_eq("first paragraph\nstill first\n\n");
2465
2466    cx.simulate_shared_keystrokes("escape").await;
2467    cx.shared_state().await.assert_eq(indoc! {
2468        "
2469        ˇ
2470        second paragraph
2471        still second
2472
2473        third paragraph
2474        "
2475    });
2476}
2477
2478#[perf]
2479#[gpui::test]
2480async fn test_multi_cursor_replay(cx: &mut gpui::TestAppContext) {
2481    let mut cx = VimTestContext::new(cx, true).await;
2482    cx.set_state(
2483        indoc! {
2484            "
2485        oˇne one one
2486
2487        two two two
2488        "
2489        },
2490        Mode::Normal,
2491    );
2492
2493    cx.simulate_keystrokes("3 g l s wow escape escape");
2494    cx.assert_state(
2495        indoc! {
2496            "
2497        woˇw wow wow
2498
2499        two two two
2500        "
2501        },
2502        Mode::Normal,
2503    );
2504
2505    cx.simulate_keystrokes("2 j 3 g l .");
2506    cx.assert_state(
2507        indoc! {
2508            "
2509        wow wow wow
2510
2511        woˇw woˇw woˇw
2512        "
2513        },
2514        Mode::Normal,
2515    );
2516}
2517
2518#[gpui::test]
2519async fn test_clipping_on_mode_change(cx: &mut gpui::TestAppContext) {
2520    let mut cx = VimTestContext::new(cx, true).await;
2521
2522    cx.set_state(
2523        indoc! {
2524        "
2525        ˇverylongline
2526        andsomelinebelow
2527        "
2528        },
2529        Mode::Normal,
2530    );
2531
2532    cx.simulate_keystrokes("v e");
2533    cx.assert_state(
2534        indoc! {
2535        "
2536        «verylonglineˇ»
2537        andsomelinebelow
2538        "
2539        },
2540        Mode::Visual,
2541    );
2542
2543    let mut pixel_position = cx.update_editor(|editor, window, cx| {
2544        let snapshot = editor.snapshot(window, cx);
2545        let current_head = editor
2546            .selections
2547            .newest_display(&snapshot.display_snapshot)
2548            .end;
2549        editor.last_bounds().unwrap().origin
2550            + editor
2551                .display_to_pixel_point(current_head, &snapshot, window, cx)
2552                .unwrap()
2553    });
2554    pixel_position.x += px(100.);
2555    // click beyond end of the line
2556    cx.simulate_click(pixel_position, Modifiers::default());
2557    cx.run_until_parked();
2558
2559    cx.assert_state(
2560        indoc! {
2561        "
2562        verylonglinˇe
2563        andsomelinebelow
2564        "
2565        },
2566        Mode::Normal,
2567    );
2568}
2569
2570#[gpui::test]
2571async fn test_wrap_selections_in_tag_line_mode(cx: &mut gpui::TestAppContext) {
2572    let mut cx = VimTestContext::new(cx, true).await;
2573
2574    let js_language = Arc::new(Language::new(
2575        LanguageConfig {
2576            name: "JavaScript".into(),
2577            wrap_characters: Some(language::WrapCharactersConfig {
2578                start_prefix: "<".into(),
2579                start_suffix: ">".into(),
2580                end_prefix: "</".into(),
2581                end_suffix: ">".into(),
2582            }),
2583            ..LanguageConfig::default()
2584        },
2585        None,
2586    ));
2587
2588    cx.update_buffer(|buffer, cx| buffer.set_language(Some(js_language), cx));
2589
2590    cx.set_state(
2591        indoc! {
2592        "
2593        ˇaaaaa
2594        bbbbb
2595        "
2596        },
2597        Mode::Normal,
2598    );
2599
2600    cx.simulate_keystrokes("shift-v j");
2601    cx.dispatch_action(WrapSelectionsInTag);
2602
2603    cx.assert_state(
2604        indoc! {
2605            "
2606            <ˇ>aaaaa
2607            bbbbb</ˇ>
2608            "
2609        },
2610        Mode::VisualLine,
2611    );
2612}
2613
2614#[gpui::test]
2615async fn test_repeat_grouping_41735(cx: &mut gpui::TestAppContext) {
2616    let mut cx = NeovimBackedTestContext::new(cx).await;
2617
2618    // typically transaction gropuing is disabled in tests, but here we need to test it.
2619    cx.update_buffer(|buffer, _cx| buffer.set_group_interval(Duration::from_millis(300)));
2620
2621    cx.set_shared_state("ˇ").await;
2622
2623    cx.simulate_shared_keystrokes("i a escape").await;
2624    cx.simulate_shared_keystrokes(". . .").await;
2625    cx.shared_state().await.assert_eq("ˇaaaa");
2626    cx.simulate_shared_keystrokes("u").await;
2627    cx.shared_state().await.assert_eq("ˇaaa");
2628}
2629
2630#[gpui::test]
2631async fn test_deactivate(cx: &mut gpui::TestAppContext) {
2632    let mut cx = VimTestContext::new(cx, true).await;
2633
2634    cx.update_global(|store: &mut SettingsStore, cx| {
2635        store.update_user_settings(cx, |settings| {
2636            settings.editor.cursor_shape = Some(settings::CursorShape::Underline);
2637        });
2638    });
2639
2640    // Assert that, while in `Normal` mode, the cursor shape is `Block` but,
2641    // after deactivating vim mode, it should revert to the one specified in the
2642    // user's settings, if set.
2643    cx.update_editor(|editor, _window, _cx| {
2644        assert_eq!(editor.cursor_shape(), CursorShape::Block);
2645    });
2646
2647    cx.disable_vim();
2648
2649    cx.update_editor(|editor, _window, _cx| {
2650        assert_eq!(editor.cursor_shape(), CursorShape::Underline);
2651    });
2652}
2653
2654// workspace::SendKeystrokes should pass literal keystrokes without triggering vim motions.
2655// When sending `" _ x`, the `_` should select the blackhole register, not trigger
2656// vim::StartOfLineDownward.
2657#[gpui::test]
2658async fn test_send_keystrokes_underscore_is_literal_46509(cx: &mut gpui::TestAppContext) {
2659    let mut cx = VimTestContext::new(cx, true).await;
2660
2661    // Bind a key to send `" _ x` which should:
2662    // `"` - start register selection
2663    // `_` - select blackhole register (NOT vim::StartOfLineDownward)
2664    // `x` - delete character into blackhole register
2665    cx.update(|_, cx| {
2666        cx.bind_keys([KeyBinding::new(
2667            "g x",
2668            workspace::SendKeystrokes("\" _ x".to_string()),
2669            Some("VimControl"),
2670        )])
2671    });
2672
2673    cx.set_state("helˇlo", Mode::Normal);
2674
2675    cx.simulate_keystrokes("g x");
2676    cx.run_until_parked();
2677
2678    cx.assert_state("helˇo", Mode::Normal);
2679}
2680
2681#[gpui::test]
2682async fn test_send_keystrokes_no_key_equivalent_mapping_46509(cx: &mut gpui::TestAppContext) {
2683    use collections::HashMap;
2684    use gpui::{KeybindingKeystroke, Keystroke, PlatformKeyboardMapper};
2685
2686    // create a mock Danish keyboard mapper
2687    // on Danish keyboards, the macOS key equivalents mapping includes: '{' -> 'Æ' and '}' -> 'Ø'
2688    // this means the `{` character is produced by the key labeled `Æ` (with shift modifier)
2689    struct DanishKeyboardMapper;
2690    impl PlatformKeyboardMapper for DanishKeyboardMapper {
2691        fn map_key_equivalent(
2692            &self,
2693            mut keystroke: Keystroke,
2694            use_key_equivalents: bool,
2695        ) -> KeybindingKeystroke {
2696            if use_key_equivalents {
2697                if keystroke.key == "{" {
2698                    keystroke.key = "Æ".to_string();
2699                }
2700                if keystroke.key == "}" {
2701                    keystroke.key = "Ø".to_string();
2702                }
2703            }
2704            KeybindingKeystroke::from_keystroke(keystroke)
2705        }
2706
2707        fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
2708            None
2709        }
2710    }
2711
2712    let mapper = DanishKeyboardMapper;
2713
2714    let keystroke_brace = Keystroke::parse("{").unwrap();
2715    let mapped_with_bug = mapper.map_key_equivalent(keystroke_brace.clone(), true);
2716    assert_eq!(
2717        mapped_with_bug.key(),
2718        "Æ",
2719        "BUG: With use_key_equivalents=true, {{ is mapped to Æ on Danish keyboard"
2720    );
2721
2722    // Fixed behavior, where the literal `{` character is preserved
2723    let mapped_fixed = mapper.map_key_equivalent(keystroke_brace.clone(), false);
2724    assert_eq!(
2725        mapped_fixed.key(),
2726        "{",
2727        "FIX: With use_key_equivalents=false, {{ stays as {{"
2728    );
2729
2730    // Same applies to }
2731    let keystroke_close = Keystroke::parse("}").unwrap();
2732    let mapped_close_bug = mapper.map_key_equivalent(keystroke_close.clone(), true);
2733    assert_eq!(mapped_close_bug.key(), "Ø");
2734    let mapped_close_fixed = mapper.map_key_equivalent(keystroke_close.clone(), false);
2735    assert_eq!(mapped_close_fixed.key(), "}");
2736
2737    let mut cx = VimTestContext::new(cx, true).await;
2738
2739    cx.update(|_, cx| {
2740        cx.bind_keys([KeyBinding::new(
2741            "g p",
2742            workspace::SendKeystrokes("{".to_string()),
2743            Some("vim_mode == normal"),
2744        )])
2745    });
2746
2747    cx.set_state(
2748        indoc! {"
2749            first paragraph
2750
2751            second paragraphˇ
2752
2753            third paragraph
2754        "},
2755        Mode::Normal,
2756    );
2757
2758    cx.simulate_keystrokes("g p");
2759    cx.run_until_parked();
2760
2761    cx.assert_state(
2762        indoc! {"
2763            first paragraph
2764            ˇ
2765            second paragraph
2766
2767            third paragraph
2768        "},
2769        Mode::Normal,
2770    );
2771}
2772
2773#[gpui::test]
2774async fn test_project_search_opens_in_normal_mode(cx: &mut gpui::TestAppContext) {
2775    VimTestContext::init(cx);
2776
2777    let fs = FakeFs::new(cx.background_executor.clone());
2778    fs.insert_tree(
2779        path!("/dir"),
2780        json!({
2781            "file_a.rs": "// File A.",
2782            "file_b.rs": "// File B.",
2783        }),
2784    )
2785    .await;
2786
2787    let project = project::Project::test(fs.clone(), [path!("/dir").as_ref()], cx).await;
2788    let window_handle =
2789        cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));
2790    let workspace = window_handle
2791        .read_with(cx, |mw, _| mw.workspace().clone())
2792        .unwrap();
2793
2794    cx.update(|cx| {
2795        VimTestContext::init_keybindings(true, cx);
2796    });
2797
2798    let cx = &mut VisualTestContext::from_window(window_handle.into(), cx);
2799
2800    workspace.update_in(cx, |workspace, window, cx| {
2801        ProjectSearchView::deploy_search(workspace, &DeploySearch::default(), window, cx)
2802    });
2803
2804    let search_view = workspace.update_in(cx, |workspace, _, cx| {
2805        workspace
2806            .active_pane()
2807            .read(cx)
2808            .items()
2809            .find_map(|item| item.downcast::<ProjectSearchView>())
2810            .expect("Project search view should be active")
2811    });
2812
2813    project_search::perform_project_search(&search_view, "File A", cx);
2814
2815    search_view.update(cx, |search_view, cx| {
2816        let vim_mode = search_view
2817            .results_editor()
2818            .read(cx)
2819            .addon::<VimAddon>()
2820            .map(|addon| addon.entity.read(cx).mode);
2821
2822        assert_eq!(vim_mode, Some(Mode::Normal));
2823    });
2824}