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

@ -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)
}
})
})