vim: Support count with [x and ]x (#22176)

Fixes: #21577
Fixes: #17245

Release Notes:

- vim: Add <count> support for [x/]x
This commit is contained in:
Conrad Irwin 2024-12-18 08:28:22 -07:00 committed by GitHub
parent a0a095c6a3
commit 2ecbd97fe8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 2 deletions

View file

@ -230,8 +230,8 @@
"ctrl-pageup": "pane::ActivatePrevItem",
"insert": "vim::InsertBefore",
// tree-sitter related commands
"[ x": "editor::SelectLargerSyntaxNode",
"] x": "editor::SelectSmallerSyntaxNode",
"[ x": "vim::SelectLargerSyntaxNode",
"] x": "vim::SelectSmallerSyntaxNode",
"] d": "editor::GoToDiagnostic",
"[ d": "editor::GoToPrevDiagnostic",
"] c": "editor::GoToHunk",

View file

@ -36,6 +36,8 @@ actions!(
SelectPrevious,
SelectNextMatch,
SelectPreviousMatch,
SelectSmallerSyntaxNode,
SelectLargerSyntaxNode,
RestoreVisualSelection,
VisualInsertEndOfLine,
VisualInsertFirstNonWhiteSpace,
@ -74,6 +76,24 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
vim.select_match(Direction::Prev, cx);
});
Vim::action(editor, cx, |vim, _: &SelectLargerSyntaxNode, cx| {
let count = Vim::take_count(cx).unwrap_or(1);
for _ in 0..count {
vim.update_editor(cx, |_, editor, cx| {
editor.select_larger_syntax_node(&Default::default(), cx);
});
}
});
Vim::action(editor, cx, |vim, _: &SelectSmallerSyntaxNode, cx| {
let count = Vim::take_count(cx).unwrap_or(1);
for _ in 0..count {
vim.update_editor(cx, |_, editor, cx| {
editor.select_smaller_syntax_node(&Default::default(), cx);
});
}
});
Vim::action(editor, cx, |vim, _: &RestoreVisualSelection, cx| {
let Some((stored_mode, reversed)) = vim.stored_visual_mode.take() else {
return;