Skip to content

Commit 16a0e3c

Browse files
committed
feat(api): add api.config.mappings.active, api.config.mappings.default (#1876)
1 parent 54b850a commit 16a0e3c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

doc/nvim-tree-lua.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,20 @@ exists.
13351335
- navigate.prev
13361336
- navigate.select
13371337

1338+
api.config.mappings.active() *nvim-tree.api.config.mappings.active()*
1339+
Retrieve a clone of the currently active mappings:
1340+
|nvim-tree-default-mappings| with |nvim-tree.view.mappings| applied.
1341+
Changing the active mappings will require a call to |nvim-tree-setup|
1342+
1343+
Return: ~
1344+
(table) as per |nvim-tree.view.mappings.list|
1345+
1346+
api.config.mappings.default() *nvim-tree.api.config.mappings.default()*
1347+
Retrieve a clone of the default mappings: |nvim-tree-default-mappings|
1348+
1349+
Return: ~
1350+
(table) as per |nvim-tree.view.mappings.list|
1351+
13381352
==============================================================================
13391353
6. MAPPINGS *nvim-tree-mappings*
13401354

lua/nvim-tree/actions/init.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,18 @@ local DEFAULT_MAPPING_CONFIG = {
399399
list = {},
400400
}
401401

402+
--- clone default for the user
403+
--- @return table
404+
function M.default_mappings_clone()
405+
return vim.deepcopy(DEFAULT_MAPPINGS)
406+
end
407+
408+
--- clone active for the user
409+
--- @return table
410+
function M.active_mappings_clone()
411+
return vim.deepcopy(M.mappings)
412+
end
413+
402414
function M.setup(opts)
403415
require("nvim-tree.actions.fs.trash").setup(opts)
404416
require("nvim-tree.actions.node.system-open").setup(opts)

lua/nvim-tree/api.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local Api = {
66
fs = { copy = {} },
77
git = {},
88
live_filter = {},
9+
config = { mappings = {} },
910
}
1011

1112
local function inject_node(f)
@@ -127,4 +128,7 @@ Api.marks.navigate.next = require("nvim-tree.marks.navigation").next
127128
Api.marks.navigate.prev = require("nvim-tree.marks.navigation").prev
128129
Api.marks.navigate.select = require("nvim-tree.marks.navigation").select
129130

131+
Api.config.mappings.active = require("nvim-tree.actions").active_mappings_clone
132+
Api.config.mappings.default = require("nvim-tree.actions").default_mappings_clone
133+
130134
return Api

0 commit comments

Comments
 (0)