feat(cmd): use cmd table instead of trying to create the cmd string. Fixes #472

This commit is contained in:
Folke Lemaitre 2023-02-07 20:56:54 +01:00
parent 0dcc9071df
commit 3c29f196f4
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 15 additions and 9 deletions

View File

@ -14,16 +14,22 @@ end
---@param cmd string ---@param cmd string
function M:_add(cmd) function M:_add(cmd)
vim.api.nvim_create_user_command(cmd, function(event) vim.api.nvim_create_user_command(cmd, function(event)
local command = {
cmd = cmd,
bang = event.bang or nil,
mods = event.smods,
args = event.fargs,
count = event.count >= 0 and event.count or nil,
}
if event.range == 1 then
command.range = { event.line1 }
elseif event.range == 2 then
command.range = { event.line1, event.line2 }
end
self:_load(cmd) self:_load(cmd)
vim.cmd( vim.cmd(command)
("%s %s%s%s %s"):format(
event.mods or "",
event.line1 == event.line2 and "" or event.line1 .. "," .. event.line2,
cmd,
event.bang and "!" or "",
event.args or ""
)
)
end, { end, {
bang = true, bang = true,
range = true, range = true,