Skip to content

Commit cf3d612

Browse files
authored
fix: nil index when swapping at first/last child (#577)
1 parent 3532f60 commit cf3d612

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lua/nvim-treesitter/textobjects/shared.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ function M.next_textobject(node, query_string, query_group, same_parent, overlap
332332

333333
local next_node = queries.find_best_match(bufnr, query_string, query_group, filter_function, scoring_function)
334334

335-
return next_node and next_node.node, next_node.metadata
335+
if next_node then
336+
return next_node.node, next_node.metadata
337+
end
336338
end
337339

338340
function M.previous_textobject(node, query_string, query_group, same_parent, overlapping_range_ok, bufnr)
@@ -367,7 +369,9 @@ function M.previous_textobject(node, query_string, query_group, same_parent, ove
367369

368370
local previous_node = queries.find_best_match(bufnr, query_string, query_group, filter_function, scoring_function)
369371

370-
return previous_node and previous_node.node, previous_node.metadata
372+
if previous_node then
373+
return previous_node.node, previous_node.metadata
374+
end
371375
end
372376

373377
return M

0 commit comments

Comments
 (0)