From be64636cfb1e75ae2fc8c7261f6e4030ec9d9a13 Mon Sep 17 00:00:00 2001 From: windwp Date: Sat, 13 Mar 2021 09:37:36 +0700 Subject: [PATCH] skip replace on special char < > --- lua/nvim-ts-autotag/internal.lua | 20 +++++++++++++++----- tests/minimal.vim | 1 - tests/renametag_spec.lua | 9 +++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 732a7a9..994086e 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -192,9 +192,6 @@ local function checkCloseTag() return false end -function M.code(cmd) - return vim.api.nvim_replace_termcodes(cmd, true, false, true) -end M.closeTag = function () local result, tag_name = checkCloseTag() if result == true and tag_name ~= nil then @@ -282,9 +279,22 @@ local function checkEndTag() end end +local function validate_rename() + local cursor = vim.api.nvim_win_get_cursor('.') + local line = vim.fn.getline(cursor[1]) + local char = line:sub(cursor[2] + 1, cursor[2] + 1) + -- only rename when last character is a word + if string.match(char,'%w') then + return true + end + return false +end + M.renameTag = function () - checkStartTag() - checkEndTag() + if validate_rename() then + checkStartTag() + checkEndTag() + end end M.attach = function (bufnr) diff --git a/tests/minimal.vim b/tests/minimal.vim index 9f5b452..390fcbf 100644 --- a/tests/minimal.vim +++ b/tests/minimal.vim @@ -17,7 +17,6 @@ set nocindent set nosmartindent set indentexpr= -TSUpdate lua << EOF diff --git a/tests/renametag_spec.lua b/tests/renametag_spec.lua index 6cd691e..427b1e0 100644 --- a/tests/renametag_spec.lua +++ b/tests/renametag_spec.lua @@ -38,6 +38,15 @@ local data = { before = [[ dsadsa ]], after = [[ dsadsa ]] }, + { + name = "html not rename close tag on char <" , + filepath = './sample/index.html', + filetype = "html", + linenr = 10, + key = [[i<]], + before = [[
dsadsa |/button> ]], + after = [[ dsadsa | ]] + }, { name = "html rename close tag with attr" , filepath = './sample/index.html',