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
@@ -1494,6 +1494,23 @@ api.config.mappings.default() *nvim-tree.api.config.mappings.default()*
|
|||||||
Return: ~
|
Return: ~
|
||||||
(table) as per |nvim-tree.view.mappings.list|
|
(table) as per |nvim-tree.view.mappings.list|
|
||||||
|
|
||||||
|
*nvim-tree.api.config.mappings.get_keymap()*
|
||||||
|
api.config.mappings.get_keymap()
|
||||||
|
Retrieves all buffer local mappings for nvim-tree.
|
||||||
|
These are the mappings that are applied by |nvim-tree.on_attach|, which
|
||||||
|
may include default mappings.
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(table) as per |nvim_buf_get_keymap()|
|
||||||
|
|
||||||
|
*nvim-tree.api.config.mappings.get_keymap()*
|
||||||
|
api.config.mappings.get_keymap_default()
|
||||||
|
Retrieves the buffer local mappings for nvim-tree that are applied by
|
||||||
|
|nvim-tree.api.config.mappings.default_on_attach()|
|
||||||
|
|
||||||
|
Return: ~
|
||||||
|
(table) as per |nvim_buf_get_keymap()|
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
6. MAPPINGS *nvim-tree-mappings*
|
6. MAPPINGS *nvim-tree-mappings*
|
||||||
|
|
||||||
|
|||||||
@@ -182,4 +182,11 @@ Api.config.mappings.default = function()
|
|||||||
return require("nvim-tree.keymap-legacy").default_mappings_clone()
|
return require("nvim-tree.keymap-legacy").default_mappings_clone()
|
||||||
end
|
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
|
return Api
|
||||||
|
|||||||
@@ -1,5 +1,24 @@
|
|||||||
local M = {}
|
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
|
-- stylua: ignore start
|
||||||
function M.default_on_attach(bufnr)
|
function M.default_on_attach(bufnr)
|
||||||
local api = require('nvim-tree.api')
|
local api = require('nvim-tree.api')
|
||||||
@@ -65,6 +84,14 @@ function M.default_on_attach(bufnr)
|
|||||||
end
|
end
|
||||||
-- stylua: ignore 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)
|
function M.setup(opts)
|
||||||
if type(opts.on_attach) ~= "function" then
|
if type(opts.on_attach) ~= "function" then
|
||||||
M.on_attach = M.default_on_attach
|
M.on_attach = M.default_on_attach
|
||||||
|
|||||||
Reference in New Issue
Block a user