add vim-specific J (with repeatability)

This commit is contained in:
Conrad Irwin 2023-09-07 11:08:07 -06:00
parent 48bb2a3321
commit 8e2e00e003
4 changed files with 72 additions and 2 deletions

View File

@ -451,6 +451,7 @@
"~": "vim::ChangeCase",
"shift-i": "vim::InsertBefore",
"shift-a": "vim::InsertAfter",
"shift-j": "vim::JoinLines",
"r": [
"vim::PushOperator",
"Replace"

View File

@ -110,11 +110,18 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(|_: &mut Workspace, _: &JoinLines, cx| {
Vim::update(cx, |vim, cx| {
vim.record_current_action(cx);
let times = vim.pop_number_operator(cx).unwrap_or(1);
let mut times = vim.pop_number_operator(cx).unwrap_or(1);
if vim.state().mode.is_visual() {
times = 1;
} else if times > 1 {
// 2J joins two lines together (same as J or 1J)
times -= 1;
}
vim.update_active_editor(cx, |editor, cx| {
editor.transact(cx, |editor, cx| {
for _ in 0..times {
editor.join_lines(editor::JoinLines, cx)
editor.join_lines(&Default::default(), cx)
}
})
})

View File

@ -286,6 +286,55 @@ async fn test_word_characters(cx: &mut gpui::TestAppContext) {
)
}
#[gpui::test]
async fn test_join_lines(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {"
ˇone
two
three
four
five
six
"})
.await;
cx.simulate_shared_keystrokes(["shift-j"]).await;
cx.assert_shared_state(indoc! {"
oneˇ two
three
four
five
six
"})
.await;
cx.simulate_shared_keystrokes(["3", "shift-j"]).await;
cx.assert_shared_state(indoc! {"
one two threeˇ four
five
six
"})
.await;
cx.set_shared_state(indoc! {"
ˇone
two
three
four
five
six
"})
.await;
cx.simulate_shared_keystrokes(["j", "v", "3", "j", "shift-j"])
.await;
cx.assert_shared_state(indoc! {"
one
two three fourˇ five
six
"})
.await;
}
#[gpui::test]
async fn test_wrapped_lines(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View File

@ -0,0 +1,13 @@
{"Put":{"state":"ˇone\ntwo\nthree\nfour\nfive\nsix\n"}}
{"Key":"shift-j"}
{"Get":{"state":"oneˇ two\nthree\nfour\nfive\nsix\n","mode":"Normal"}}
{"Key":"3"}
{"Key":"shift-j"}
{"Get":{"state":"one two threeˇ four\nfive\nsix\n","mode":"Normal"}}
{"Put":{"state":"ˇone\ntwo\nthree\nfour\nfive\nsix\n"}}
{"Key":"j"}
{"Key":"v"}
{"Key":"3"}
{"Key":"j"}
{"Key":"shift-j"}
{"Get":{"state":"one\ntwo three fourˇ five\nsix\n","mode":"Normal"}}