Compare commits

..

4 Commits

Author SHA1 Message Date
1624866a13
Merge pull request #201 from inferst/fix/tsx-node-renaming
fix: tsx node renaming
2024-07-16 13:50:01 -05:00
Mikhail Morozov
7f9f55b285 chore: move text node filtering to utils function 2024-07-16 14:26:15 +03:00
Mikhail Morozov
0782035107 Merge branch 'main' of github.com:inferst/nvim-ts-autotag into fix/tsx-node-renaming 2024-07-15 01:46:33 +03:00
Mikhail Morozov
220fe15d97 fix: tsx node renaming 2024-07-13 14:32:00 +03:00

View File

@ -63,7 +63,20 @@ end
M.get_node_text = function(node)
local _, txt = pcall(get_node_text, node, vim.api.nvim_get_current_buf())
return vim.split(txt, "\n") or {}
local texts = vim.split(txt, "\n")
local filtered = {}
-- For some nodes (tsx) 'vim.treesitter.get_node_text' can return empty lines or lines with spaces
-- We have to exclude them
for i = 1, #texts do
local text = texts[i]:gsub("^%s*(.-)%s*$", "%1")
if text ~= "" then
filtered[#filtered + 1] = text
end
end
return filtered or {}
end
-- Stolen from nvim `0.10.0` for `0.9.5` users