Fix ctrl-r with no register (#13184)

Conrad Irwin created

Release Notes:

- N/A

Change summary

assets/keymaps/vim.json                      | 7 +++++++
crates/vim/src/insert.rs                     | 4 ++++
crates/vim/src/vim.rs                        | 1 +
crates/vim/test_data/test_insert_ctrl_r.json | 5 +++++
4 files changed, 17 insertions(+)

Detailed changes

assets/keymaps/vim.json 🔗

@@ -657,6 +657,13 @@
       "ctrl-[": ["vim::SwitchMode", "Normal"]
     }
   },
+  {
+    "context": "Editor && vim_mode == insert && VimWaiting",
+    "bindings": {
+      "escape": "vim::NormalBefore",
+      "ctrl-[": "vim::NormalBefore"
+    }
+  },
   {
     "context": "BufferSearchBar && !in_replace",
     "bindings": {

crates/vim/src/insert.rs 🔗

@@ -124,5 +124,9 @@ mod test {
         cx.set_shared_state("heˇllo\n").await;
         cx.simulate_shared_keystrokes("y y i ctrl-r \"").await;
         cx.shared_state().await.assert_eq("hehello\nˇllo\n");
+
+        cx.simulate_shared_keystrokes("ctrl-r x ctrl-r escape")
+            .await;
+        cx.shared_state().await.assert_eq("hehello\nˇllo\n");
     }
 }

crates/vim/src/vim.rs 🔗

@@ -896,6 +896,7 @@ impl Vim {
                             )
                         }
                     });
+                    vim.clear_operator(cx);
                 }
                 _ => {
                     vim.select_register(text, cx);

crates/vim/test_data/test_insert_ctrl_r.json 🔗

@@ -5,3 +5,8 @@
 {"Key":"ctrl-r"}
 {"Key":"\""}
 {"Get":{"state":"hehello\nˇllo\n","mode":"Insert"}}
+{"Key":"ctrl-r"}
+{"Key":"x"}
+{"Key":"ctrl-r"}
+{"Key":"escape"}
+{"Get":{"state":"hehello\nˇllo\n","mode":"Insert"}}