Skip to content

Commit d8aa8ea

Browse files
committed
feat: allow specifying mapping_options once for all mappings, part of #242
1 parent 0c59927 commit d8aa8ea

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,15 @@ use {
144144
window = {
145145
position = "left",
146146
width = 40,
147+
mapping_options = {
148+
noremap = true,
149+
nowait = true,
150+
},
147151
mappings = {
148-
["<space>"] = "toggle_node",
152+
["<space>"] = {
153+
"toggle_node",
154+
nowait = false, -- disable `nowait` if you have existing combos starting with this char that you want to use
155+
},
149156
["<2-LeftMouse>"] = "open",
150157
["<cr>"] = "open",
151158
["S"] = "open_split",

doc/neo-tree.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,10 @@ You probably want #2:
319319
CUSTOM MAPPINGS WITH ARGUMENTS
320320

321321
If you want to include options for your mappings, such as `nowait`, you can
322-
map a key to a table that consists of the command and any options you want to
323-
use.
322+
set this for all mappings using the `mapping_options` key, or on individual
323+
mappings by specifiying them as a table that consists of the command and any
324+
options you want to use. If both are specified, the mapping merges with and
325+
overrides the global `mapping_options`
324326

325327
The command can be either the string name of a built-in command, or a
326328
function, and is specified either as the first element in the table or by
@@ -329,6 +331,10 @@ assigning it to the `command` key:
329331
require("neo-tree").setup({
330332
filesystem = {
331333
window = {
334+
mapping_options = {
335+
noremap = true,
336+
nowait = false,
337+
},
332338
mappings = {
333339
["?"] = {
334340
function(state)

lua/neo-tree/ui/renderer.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,13 @@ create_window = function(state)
644644
["noop"] = true,
645645
}
646646
local mappings = utils.get_value(state, "window.mappings", {}, true)
647+
local mapping_options = utils.get_value(state, "window.mapping_options", { noremap = true }, true)
647648
for cmd, func in pairs(mappings) do
648649
if utils.truthy(func) then
649650
if skip_this_mapping[func] then
650651
log.trace("Skipping mapping for %s", cmd)
651652
else
652-
local map_options = { noremap = true }
653+
local map_options = vim.deepcopy(mapping_options)
653654
if type(func) == "table" then
654655
for key, value in pairs(func) do
655656
if key ~= "command" and key ~= 1 then

0 commit comments

Comments
 (0)