fix(mappings): expr for insert mode (#2458)
This commit is contained in:
@@ -240,9 +240,14 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
|
|||||||
key_func = actions[key_func]
|
key_func = actions[key_func]
|
||||||
elseif type(key_func) == "table" then
|
elseif type(key_func) == "table" then
|
||||||
if key_func.type == "command" then
|
if key_func.type == "command" then
|
||||||
a.nvim_buf_set_keymap(prompt_bufnr, mode, key_bind, key_func[1], opts or {
|
vim.keymap.set(
|
||||||
silent = true,
|
mode,
|
||||||
})
|
key_bind,
|
||||||
|
key_func[1],
|
||||||
|
vim.tbl_extend("force", opts or {
|
||||||
|
silent = true,
|
||||||
|
}, { buffer = prompt_bufnr })
|
||||||
|
)
|
||||||
return
|
return
|
||||||
elseif key_func.type == "action_key" then
|
elseif key_func.type == "action_key" then
|
||||||
key_func = actions[key_func[1]]
|
key_func = actions[key_func[1]]
|
||||||
@@ -254,10 +259,11 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
|
|||||||
local key_id = assign_function(prompt_bufnr, key_func)
|
local key_id = assign_function(prompt_bufnr, key_func)
|
||||||
local prefix
|
local prefix
|
||||||
|
|
||||||
local map_string
|
local rhs
|
||||||
if opts.expr then
|
if opts.expr then
|
||||||
map_string =
|
rhs = function()
|
||||||
string.format([[luaeval("require('telescope.mappings').execute_keymap(%s, %s)")]], prompt_bufnr, key_id)
|
return require("telescope.mappings").execute_keymap(prompt_bufnr, key_id)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if mode == "i" and not opts.expr then
|
if mode == "i" and not opts.expr then
|
||||||
prefix = "<cmd>"
|
prefix = "<cmd>"
|
||||||
@@ -267,11 +273,9 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
|
|||||||
prefix = ":"
|
prefix = ":"
|
||||||
end
|
end
|
||||||
|
|
||||||
map_string =
|
rhs = string.format("%slua require('telescope.mappings').execute_keymap(%s, %s)<CR>", prefix, prompt_bufnr, key_id)
|
||||||
string.format("%slua require('telescope.mappings').execute_keymap(%s, %s)<CR>", prefix, prompt_bufnr, key_id)
|
|
||||||
end
|
end
|
||||||
|
vim.keymap.set(mode, key_bind, rhs, vim.tbl_extend("force", opts, { buffer = prompt_bufnr }))
|
||||||
a.nvim_buf_set_keymap(prompt_bufnr, mode, key_bind, map_string, opts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local extract_keymap_opts = function(key_func)
|
local extract_keymap_opts = function(key_func)
|
||||||
@@ -342,13 +346,16 @@ mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: conni2461 we no longer need this workaround and could just call the actual function
|
||||||
mappings.execute_keymap = function(prompt_bufnr, keymap_identifier)
|
mappings.execute_keymap = function(prompt_bufnr, keymap_identifier)
|
||||||
local key_func = keymap_store[prompt_bufnr][keymap_identifier]
|
local key_func = keymap_store[prompt_bufnr][keymap_identifier]
|
||||||
|
|
||||||
assert(key_func, string.format("Unsure of how we got this failure: %s %s", prompt_bufnr, keymap_identifier))
|
assert(key_func, string.format("Unsure of how we got this failure: %s %s", prompt_bufnr, keymap_identifier))
|
||||||
|
|
||||||
key_func(prompt_bufnr)
|
-- return the result because of expr for insert
|
||||||
|
local ret = key_func(prompt_bufnr)
|
||||||
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeKeymap" })
|
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeKeymap" })
|
||||||
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
mappings.clear = function(prompt_bufnr)
|
mappings.clear = function(prompt_bufnr)
|
||||||
|
|||||||
Reference in New Issue
Block a user