Skip to content

Commit

Permalink
feat: count support for motions
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Aug 17, 2024
1 parent 2036a3c commit dc29c79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lua/tailwind-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lua/tailwind-tools/motions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions tests/motions/jump_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dc29c79

Please sign in to comment.