From dc29c790472ef2e4886cf0d89f5599cdd4f470ad Mon Sep 17 00:00:00 2001 From: Luckas Date: Sat, 17 Aug 2024 07:56:38 +0300 Subject: [PATCH] feat: count support for motions --- README.md | 5 ++++- lua/tailwind-tools/init.lua | 4 ++-- lua/tailwind-tools/motions.lua | 8 ++++++-- tests/motions/jump_spec.lua | 6 ++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7534995..70d8e31 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,9 @@ Available commands: - `TailwindNextClass`: moves the cursor to the nearest next class node. - `TailwindPrevClass`: moves the cursor to the nearest previous class node. +> [!NOTE] +> In normal mode, `TailwindNextClass` and `TailwindPrevClass` can be used with a count to jump through multiple classes at once. + ## Utilities ### nvim-cmp @@ -171,7 +174,7 @@ Available subcommands: - `classes`: Lists all the classes in the current file and allows to jump to the selected location. -- `utilities`: Lists all utility classes available in the current projects with a custom callback. +- `utilities`: Lists all utility classes available in the current project with a custom callback. ## Extension diff --git a/lua/tailwind-tools/init.lua b/lua/tailwind-tools/init.lua index 27431f0..29499e9 100644 --- a/lua/tailwind-tools/init.lua +++ b/lua/tailwind-tools/init.lua @@ -18,8 +18,8 @@ local function register_usercmd() usercmd("TailwindColorEnable", lsp.enable_color, { nargs = 0 }) usercmd("TailwindColorDisable", lsp.disable_color, { nargs = 0 }) usercmd("TailwindColorToggle", lsp.toggle_colors, { nargs = 0 }) - usercmd("TailwindNextClass", motions.move_to_next_class, { nargs = 0 }) - usercmd("TailwindPrevClass", motions.move_to_prev_class, { nargs = 0 }) + usercmd("TailwindNextClass", motions.move_to_next_class, { nargs = 0, range = "%" }) + usercmd("TailwindPrevClass", motions.move_to_prev_class, { nargs = 0, range = "%" }) usercmd("TailwindSortSync", function() lsp.sort_classes(true) end, { nargs = 0 }) usercmd("TailwindSortSelectionSync", function() lsp.sort_selection(true) end, { range = "%" }) end diff --git a/lua/tailwind-tools/motions.lua b/lua/tailwind-tools/motions.lua index 954cb60..dca447d 100644 --- a/lua/tailwind-tools/motions.lua +++ b/lua/tailwind-tools/motions.lua @@ -29,11 +29,15 @@ local move_to_class = function(comp) end M.move_to_next_class = function() - move_to_class(function(a, b) return a > b end) + for _ = 1, vim.v.count1 do + move_to_class(function(a, b) return a > b end) + end end M.move_to_prev_class = function() - move_to_class(function(a, b) return a < b end) + for _ = 1, vim.v.count1 do + move_to_class(function(a, b) return a < b end) + end end return M diff --git a/tests/motions/jump_spec.lua b/tests/motions/jump_spec.lua index ec17551..86947f6 100644 --- a/tests/motions/jump_spec.lua +++ b/tests/motions/jump_spec.lua @@ -28,4 +28,10 @@ describe("jump motion:", function() vim.cmd.TailwindPrevClass() assert_cursor(11, 14) end) + + it("should go to the last class", function() + vim.cmd.normal("3") + vim.cmd.TailwindNextClass() + assert_cursor(13, 16) + end) end)