skip replace on special char < >

This commit is contained in:
windwp 2021-03-13 09:37:36 +07:00
parent c404074515
commit be64636cfb
3 changed files with 24 additions and 6 deletions

View File

@ -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)

View File

@ -17,7 +17,6 @@ set nocindent
set nosmartindent
set indentexpr=
TSUpdate
lua << EOF

View File

@ -38,6 +38,15 @@ local data = {
before = [[<di|v class="lla"> dsadsa </div> ]],
after = [[<lala| class="lla"> dsadsa </lala|> ]]
},
{
name = "html not rename close tag on char <" ,
filepath = './sample/index.html',
filetype = "html",
linenr = 10,
key = [[i<]],
before = [[<div class="lla"> dsadsa |/button> ]],
after = [[<div| class="lla"> dsadsa |</button> ]]
},
{
name = "html rename close tag with attr" ,
filepath = './sample/index.html',