vim: subword motions (#8725)
Add subword motions to vim, inspired by [nvim-spider](https://github.com/chrisgrieser/nvim-spider), [CamelCaseMotion](https://github.com/bkad/CamelCaseMotion). Release Notes: - Added subword motions to vim
This commit is contained in:
parent
467a179837
commit
d247086b21
6 changed files with 491 additions and 93 deletions
|
@ -407,11 +407,12 @@ pub(crate) fn normal_replace(text: Arc<str>, cx: &mut WindowContext) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use gpui::TestAppContext;
|
||||
use gpui::{KeyBinding, TestAppContext};
|
||||
use indoc::indoc;
|
||||
use settings::SettingsStore;
|
||||
|
||||
use crate::{
|
||||
motion,
|
||||
state::Mode::{self},
|
||||
test::{NeovimBackedTestContext, VimTestContext},
|
||||
VimSettings,
|
||||
|
@ -1045,4 +1046,73 @@ mod test {
|
|||
cx.simulate_shared_keystrokes(["4", "$"]).await;
|
||||
cx.assert_shared_state("aa\nbb\ncˇc").await;
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_subword_motions(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = VimTestContext::new(cx, true).await;
|
||||
cx.update(|cx| {
|
||||
cx.bind_keys(vec![
|
||||
KeyBinding::new(
|
||||
"w",
|
||||
motion::NextSubwordStart {
|
||||
ignore_punctuation: false,
|
||||
},
|
||||
Some("Editor && VimControl && !VimWaiting && !menu"),
|
||||
),
|
||||
KeyBinding::new(
|
||||
"b",
|
||||
motion::PreviousSubwordStart {
|
||||
ignore_punctuation: false,
|
||||
},
|
||||
Some("Editor && VimControl && !VimWaiting && !menu"),
|
||||
),
|
||||
KeyBinding::new(
|
||||
"e",
|
||||
motion::NextSubwordEnd {
|
||||
ignore_punctuation: false,
|
||||
},
|
||||
Some("Editor && VimControl && !VimWaiting && !menu"),
|
||||
),
|
||||
KeyBinding::new(
|
||||
"g e",
|
||||
motion::PreviousSubwordEnd {
|
||||
ignore_punctuation: false,
|
||||
},
|
||||
Some("Editor && VimControl && !VimWaiting && !menu"),
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
cx.assert_binding_normal(
|
||||
["w"],
|
||||
indoc! {"ˇassert_binding"},
|
||||
indoc! {"assert_ˇbinding"},
|
||||
);
|
||||
// Special case: In 'cw', 'w' acts like 'e'
|
||||
cx.assert_binding(
|
||||
["c", "w"],
|
||||
indoc! {"ˇassert_binding"},
|
||||
Mode::Normal,
|
||||
indoc! {"ˇ_binding"},
|
||||
Mode::Insert,
|
||||
);
|
||||
|
||||
cx.assert_binding_normal(
|
||||
["e"],
|
||||
indoc! {"ˇassert_binding"},
|
||||
indoc! {"asserˇt_binding"},
|
||||
);
|
||||
|
||||
cx.assert_binding_normal(
|
||||
["b"],
|
||||
indoc! {"assert_ˇbinding"},
|
||||
indoc! {"ˇassert_binding"},
|
||||
);
|
||||
|
||||
cx.assert_binding_normal(
|
||||
["g", "e"],
|
||||
indoc! {"assert_bindinˇg"},
|
||||
indoc! {"asserˇt_binding"},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue