Skip to content

Commit

Permalink
Merge pull request #201 from inferst/fix/tsx-node-renaming
Browse files Browse the repository at this point in the history
fix: tsx node renaming
  • Loading branch information
PriceHiller authored Jul 16, 2024
2 parents 26c365c + 7f9f55b commit 1624866
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lua/nvim-ts-autotag/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1624866

Please sign in to comment.