Does not work on replaces, cuts, and pasts
Closed this issue · 3 comments
It works just perfectly when you explicitly enter the insert mode, edit the tag, and leave – and this is just perfect. But I always facing situations when I want to use the replace mode, paste, or any other action that does not enter the insert mode. Would be very cool if this plugin can support any opeartions!
I guess what you want is out of the charge of this plugin. I mean, this is a plugin that is only for auto-completing JSX tags when inserting, which means if you want it to work as you expect it, then you may want to use formatters to format everything right after replacing, cutting, or pasting, including all your codes and the JSX tags, too.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I've done something like this:
local wrap_with_paste_autocmds = function(action)
return function()
vim.api.nvim_exec_autocmds("User", { pattern = "PastePre" })
action()
vim.schedule(function()
vim.api.nvim_exec_autocmds("User", { pattern = "PastePost" })
end)
end
end
vim.keymap.set(
{ "n" },
"p",
wrap_with_paste_autocmds(function()
vim.cmd("norm! p")
end)
)
vim.keymap.set(
{ "n" },
"P",
wrap_with_paste_autocmds(function()
vim.cmd("norm! P")
end)
)
local autotag_group = vim.api.nvim_create_augroup("autotag_group_custom", {})
-- rename tags on paste also
vim.api.nvim_create_autocmd({ "User" }, {
group = autotag_group,
pattern = { "PastePost" },
callback = function()
if require("nvim-ts-autotag.config.plugin").get_opts(vim.bo.filetype).enable_rename then
vim.cmd.undojoin() -- optional: makes sure the rename is a single undo
require("nvim-ts-autotag.internal").rename_tag()
end
end,
})
In that way, whenever I paste something I manually trigger renaming. It's can fail when internals change, but for now it works really well for me :)
You can add simmilar mappings for other actions like replaces, cuts etc