From 220fe15d97ce0e3170f6fe662c0ae6532bd91953 Mon Sep 17 00:00:00 2001 From: Mikhail Morozov Date: Sat, 13 Jul 2024 14:32:00 +0300 Subject: [PATCH] fix: tsx node renaming --- lua/nvim-ts-autotag/internal.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 2459624..a7eec58 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -284,8 +284,20 @@ local function validate_tag_regex(node, start_regex, end_regex) if node == nil then return false end + local texts = utils.get_node_text(node) - if string.match(texts[1], start_regex) and string.match(texts[#texts], end_regex) then + 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 + + if string.match(filtered[1], start_regex) and string.match(filtered[#filtered], end_regex) then return true end return false