Re-entrant SendKeystrokes (#20277)

Release Notes:

- Improved `workspace::SendKeystrokes` to support re-binding keys. For
example you can now do: `"x": ["workspace::SendKeystrokes", "\" _ x"]`
in vim mode to ensure that `x` does not clobber your clipboard.
- Improved key binding documentation
This commit is contained in:
Conrad Irwin 2024-11-05 21:18:16 -07:00 committed by GitHub
parent 50069a2153
commit 38b1940251
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 137 additions and 475 deletions

View file

@ -1403,6 +1403,32 @@ async fn test_remap_nested_pineapple(cx: &mut gpui::TestAppContext) {
cx.shared_state().await.assert_eq("🍍ˇ");
}
#[gpui::test]
async fn test_remap_recursion(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.update(|cx| {
cx.bind_keys([KeyBinding::new(
"x",
workspace::SendKeystrokes("\" _ x".to_string()),
Some("VimControl"),
)]);
cx.bind_keys([KeyBinding::new(
"y",
workspace::SendKeystrokes("2 x".to_string()),
Some("VimControl"),
)])
});
cx.neovim.exec("noremap x \"_x").await;
cx.neovim.exec("map y 2x").await;
cx.set_shared_state("ˇhello").await;
cx.simulate_shared_keystrokes("d l").await;
cx.shared_clipboard().await.assert_eq("h");
cx.simulate_shared_keystrokes("y").await;
cx.shared_clipboard().await.assert_eq("h");
cx.shared_state().await.assert_eq("ˇlo");
}
#[gpui::test]
async fn test_escape_while_waiting(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View file

@ -0,0 +1,11 @@
{"Exec":{"command":"noremap x \"_x"}}
{"Exec":{"command":"map y 2x"}}
{"Put":{"state":"ˇhello"}}
{"Key":"d"}
{"Key":"l"}
{"Get":{"state":"ˇello","mode":"Normal"}}
{"ReadRegister":{"name":"\"","value":"h"}}
{"Key":"y"}
{"Get":{"state":"ˇlo","mode":"Normal"}}
{"ReadRegister":{"name":"\"","value":"h"}}
{"Get":{"state":"ˇlo","mode":"Normal"}}