This commit is contained in:
hrsh7th
2022-01-07 01:06:29 +09:00
parent 796f925915
commit 5533c352c6

View File

@@ -122,8 +122,9 @@ keymap.get_mapping = function(mode, lhs)
if keymap.equals(map.lhs, lhs) then if keymap.equals(map.lhs, lhs) then
return { return {
lhs = map.lhs, lhs = map.lhs,
rhs = map.rhs, rhs = map.rhs or '',
expr = map.expr == 1, expr = map.expr == 1,
callback = map.callback,
noremap = map.noremap == 1, noremap = map.noremap == 1,
script = map.script == 1, script = map.script == 1,
silent = map.silent == 1, silent = map.silent == 1,
@@ -137,8 +138,9 @@ keymap.get_mapping = function(mode, lhs)
if keymap.equals(map.lhs, lhs) then if keymap.equals(map.lhs, lhs) then
return { return {
lhs = map.lhs, lhs = map.lhs,
rhs = map.rhs, rhs = map.rhs or '',
expr = map.expr == 1, expr = map.expr == 1,
callback = map.callback,
noremap = map.noremap == 1, noremap = map.noremap == 1,
script = map.script == 1, script = map.script == 1,
silent = map.silent == 1, silent = map.silent == 1,
@@ -152,6 +154,7 @@ keymap.get_mapping = function(mode, lhs)
lhs = lhs, lhs = lhs,
rhs = lhs, rhs = lhs,
expr = false, expr = false,
callback = nil,
noremap = true, noremap = true,
script = false, script = false,
silent = false, silent = false,
@@ -172,7 +175,19 @@ keymap.evacuate = function(bufnr, mode, lhs)
end end
-- Keep existing mapping as <Plug> mapping. We escape fisrt recursive key sequence. See `:help recursive_mapping`) -- Keep existing mapping as <Plug> mapping. We escape fisrt recursive key sequence. See `:help recursive_mapping`)
local rhs = map.rhs local rhs, callback = '', nil
if map.callback then
callback = function(...)
local keys = map.callback(...)
if map.noremap then
return keys
end
vim.api.nvim_feedkeys(keymap.t(keymap.recursive(bufnr, mode, lhs, keys)), 'i', true)
return keymap.t('<Ignore>')
end
else
rhs = map.rhs
if not map.noremap and map.expr then if not map.noremap and map.expr then
-- remap & expr mapping should evacuate as <Plug> mapping with solving recursive mapping. -- remap & expr mapping should evacuate as <Plug> mapping with solving recursive mapping.
rhs = function() rhs = function()
@@ -196,11 +211,13 @@ keymap.evacuate = function(bufnr, mode, lhs)
-- noremap & non-expr mapping doesn't need to evacuate. -- noremap & non-expr mapping doesn't need to evacuate.
return { keys = rhs, mode = 'it' .. (map.noremap and 'n' or '') } return { keys = rhs, mode = 'it' .. (map.noremap and 'n' or '') }
end end
end
local fallback = ('<Plug>(cmp.utils.keymap.evacuate:%s)'):format(map.lhs) local fallback = ('<Plug>(cmp.utils.keymap.evacuate:%s)'):format(map.lhs)
keymap.set_map(bufnr, mode, fallback, rhs, { keymap.set_map(bufnr, mode, fallback, rhs, {
expr = map.expr, expr = map.expr,
noremap = map.noremap, noremap = map.noremap,
callback = callback,
script = map.script, script = map.script,
silent = mode ~= 'c', -- I can't understand but it solves the #427 (wilder.nvim's mapping does not work if silent=true in cmdline mode...) silent = mode ~= 'c', -- I can't understand but it solves the #427 (wilder.nvim's mapping does not work if silent=true in cmdline mode...)
}) })