Vim: enable sending multiple keystrokes from custom keybinding (#7965)
Release Notes: - Added `workspace::SendKeystrokes` to enable mapping from one key to a sequence of others ([#7033](https://github.com/zed-industries/zed/issues/7033)). Improves #7033. Big thank you to @ConradIrwin who did most of the heavy lifting on this one. This PR allows the user to send multiple keystrokes via custom keybinding. For example, the following keybinding would go down four lines and then right four characters. ```json [ { "context": "Editor && VimControl && !VimWaiting && !menu", "bindings": { "g z": [ "workspace::SendKeystrokes", "j j j j l l l l" ], } } ] ``` --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
@@ -884,3 +884,70 @@ async fn test_rename(cx: &mut gpui::TestAppContext) {
|
||||
rename_request.next().await.unwrap();
|
||||
cx.assert_state("const afterˇ = 2; console.log(after)", Mode::Normal)
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_remap(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = VimTestContext::new(cx, true).await;
|
||||
|
||||
// test moving the cursor
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"g z",
|
||||
workspace::SendKeystrokes("l l l l".to_string()),
|
||||
None,
|
||||
)])
|
||||
});
|
||||
cx.set_state("ˇ123456789", Mode::Normal);
|
||||
cx.simulate_keystrokes(["g", "z"]);
|
||||
cx.assert_state("1234ˇ56789", Mode::Normal);
|
||||
|
||||
// test switching modes
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"g y",
|
||||
workspace::SendKeystrokes("i f o o escape l".to_string()),
|
||||
None,
|
||||
)])
|
||||
});
|
||||
cx.set_state("ˇ123456789", Mode::Normal);
|
||||
cx.simulate_keystrokes(["g", "y"]);
|
||||
cx.assert_state("fooˇ123456789", Mode::Normal);
|
||||
|
||||
// test recursion
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"g x",
|
||||
workspace::SendKeystrokes("g z g y".to_string()),
|
||||
None,
|
||||
)])
|
||||
});
|
||||
cx.set_state("ˇ123456789", Mode::Normal);
|
||||
cx.simulate_keystrokes(["g", "x"]);
|
||||
cx.assert_state("1234fooˇ56789", Mode::Normal);
|
||||
|
||||
cx.executor().allow_parking();
|
||||
|
||||
// test command
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"g w",
|
||||
workspace::SendKeystrokes(": j enter".to_string()),
|
||||
None,
|
||||
)])
|
||||
});
|
||||
cx.set_state("ˇ1234\n56789", Mode::Normal);
|
||||
cx.simulate_keystrokes(["g", "w"]);
|
||||
cx.assert_state("1234ˇ 56789", Mode::Normal);
|
||||
|
||||
// test leaving command
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys([KeyBinding::new(
|
||||
"g u",
|
||||
workspace::SendKeystrokes("g w g z".to_string()),
|
||||
None,
|
||||
)])
|
||||
});
|
||||
cx.set_state("ˇ1234\n56789", Mode::Normal);
|
||||
cx.simulate_keystrokes(["g", "u"]);
|
||||
cx.assert_state("1234 567ˇ89", Mode::Normal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user