fix(map_util): insert bindings for <Plug>, <Cmd> and :Cmd work

Co-authored-by: Oliver Marshall <olivershawmarshall@gmail.com>
This commit is contained in:
Paul Stemmet 2024-08-18 18:08:49 +00:00
parent c5775a888a
commit 26fb642ff3
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
1 changed files with 7 additions and 11 deletions

View File

@ -35,19 +35,15 @@ M.create_maps_to_plug = function(bufnr, mode, bindings, prefix)
end end
end end
-- Prefix with <Plug> unless this is a <Cmd> or :Cmd mapping -- Prefix with <Plug> unless this is a <Cmd> or :Cmd mapping
if type(rhs) == "string" and not rhs:match("[<:]") then if type(rhs) == "string" then
if not rhs:match("[<:]") then
rhs = "<Plug>" .. prefix .. rhs rhs = "<Plug>" .. prefix .. rhs
end end
if mode == "i" then if mode == "i" then
-- HACK for some reason I can't get plug mappings to work in insert mode rhs = "<C-o>" .. rhs
for _, map in ipairs(maps) do
if map.lhs == rhs then
---@diagnostic disable-next-line: cast-local-type
rhs = map.callback or map.rhs
break
end
end end
end end
---@cast rhs string ---@cast rhs string
vim.keymap.set(mode, lhs, rhs, opts) vim.keymap.set(mode, lhs, rhs, opts)
end end