-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd7de68
commit 87b507e
Showing
6 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local M = {} | ||
|
||
local treesitter = require("tailwind-tools.treesitter") | ||
|
||
M.move_to_next_class = function() | ||
local nodes = treesitter.get_class_nodes(0, true) | ||
|
||
if not nodes then return end | ||
|
||
local cursor_row, cursor_col = unpack(vim.api.nvim_win_get_cursor(0)) | ||
|
||
table.sort(nodes, function(a, b) | ||
local a_row, a_col = treesitter.get_class_range(a, 0) | ||
local b_row, b_col = treesitter.get_class_range(b, 0) | ||
return a_row == b_row and a_col < b_col or a_row < b_row | ||
end) | ||
|
||
for _, node in ipairs(nodes) do | ||
local node_row, node_col = treesitter.get_class_range(node, 0) | ||
|
||
if node_row > cursor_row - 1 or (node_row == cursor_row - 1 and node_col > cursor_col) then | ||
return vim.api.nvim_win_set_cursor(0, { node_row + 1, node_col }) | ||
end | ||
end | ||
end | ||
|
||
M.move_to_prev_class = function() | ||
local nodes = treesitter.get_class_nodes(0, true) | ||
|
||
if not nodes then return end | ||
|
||
local cursor_row, cursor_col = unpack(vim.api.nvim_win_get_cursor(0)) | ||
|
||
table.sort(nodes, function(a, b) | ||
local a_row, a_col = treesitter.get_class_range(a, 0) | ||
local b_row, b_col = treesitter.get_class_range(b, 0) | ||
return a_row == b_row and a_col > b_col or a_row > b_row | ||
end) | ||
|
||
for _, node in ipairs(nodes) do | ||
local node_row, node_col = treesitter.get_class_range(node, 0) | ||
|
||
if node_row < cursor_row - 1 or (node_row == cursor_row - 1 and node_col < cursor_col) then | ||
return vim.api.nvim_win_set_cursor(0, { node_row + 1, node_col }) | ||
end | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Test</title> | ||
</head> | ||
|
||
<body> | ||
<div class="font-bold text-xl">Test</div> | ||
<div class="container mx-auto p-4 bg-gray-100"> | ||
<div class="text-2xl font-bold mb-4"> | ||
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint | ||
cillum sint consectetur cupidatat. | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local assert = require("luassert") | ||
|
||
local function assert_cursor(expected_row, expected_col) | ||
local row, col = unpack(vim.api.nvim_win_get_cursor(0)) | ||
assert.same(expected_row, row, "Mismatched row") | ||
assert.same(expected_col, col, "Mismatched col") | ||
end | ||
|
||
describe("jump motion:", function() | ||
vim.cmd.edit("tests/motions/index.html") | ||
|
||
it("should go to the next class", function() | ||
vim.cmd.TailwindNextClass() | ||
assert_cursor(11, 14) | ||
vim.cmd.TailwindNextClass() | ||
assert_cursor(12, 14) | ||
vim.cmd.TailwindNextClass() | ||
assert_cursor(13, 16) | ||
vim.cmd.TailwindNextClass() | ||
assert_cursor(13, 16) | ||
end) | ||
|
||
it("should go to the prev class", function() | ||
vim.cmd.TailwindPrevClass() | ||
assert_cursor(12, 14) | ||
vim.cmd.TailwindPrevClass() | ||
assert_cursor(11, 14) | ||
vim.cmd.TailwindPrevClass() | ||
assert_cursor(11, 14) | ||
end) | ||
end) |