feat(api): add api.config.mappings.get_keymap and get_keymap_default (#2056)
* feat(api): add api.config.mappings.get_keymap and get_keymap_default * feat(api): add api.config.mappings.get_keymap and get_keymap_default
This commit is contained in:
committed by
GitHub
parent
1d79a64a88
commit
4f036342f1
@@ -182,4 +182,11 @@ Api.config.mappings.default = function()
|
||||
return require("nvim-tree.keymap-legacy").default_mappings_clone()
|
||||
end
|
||||
|
||||
Api.config.mappings.get_keymap = function()
|
||||
return require("nvim-tree.keymap").get_keymap()
|
||||
end
|
||||
Api.config.mappings.get_keymap_default = function()
|
||||
return require("nvim-tree.keymap").get_keymap_default()
|
||||
end
|
||||
|
||||
return Api
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
local M = {}
|
||||
|
||||
--- Apply mappings to a scratch buffer and return buffer local mappings
|
||||
--- @param fn function(bufnr) on_attach or default_on_attach
|
||||
--- @return table as per vim.api.nvim_buf_get_keymap
|
||||
local function generate_keymap(fn)
|
||||
-- create an unlisted scratch buffer
|
||||
local scratch_bufnr = vim.api.nvim_create_buf(false, true)
|
||||
|
||||
-- apply mappings
|
||||
fn(scratch_bufnr)
|
||||
|
||||
-- retrieve all
|
||||
local keymap = vim.api.nvim_buf_get_keymap(scratch_bufnr, "")
|
||||
|
||||
-- delete the scratch buffer
|
||||
vim.api.nvim_buf_delete(scratch_bufnr, { force = true })
|
||||
|
||||
return keymap
|
||||
end
|
||||
|
||||
-- stylua: ignore start
|
||||
function M.default_on_attach(bufnr)
|
||||
local api = require('nvim-tree.api')
|
||||
@@ -65,6 +84,14 @@ function M.default_on_attach(bufnr)
|
||||
end
|
||||
-- stylua: ignore end
|
||||
|
||||
function M.get_keymap()
|
||||
return generate_keymap(M.on_attach)
|
||||
end
|
||||
|
||||
function M.get_keymap_default()
|
||||
return generate_keymap(M.default_on_attach)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
if type(opts.on_attach) ~= "function" then
|
||||
M.on_attach = M.default_on_attach
|
||||
|
||||
Reference in New Issue
Block a user