Skip to content

Commit 54b622d

Browse files
authored
feat: allow to pass function to fuzzy_finder_mappings (#1423)
1 parent 16d1b19 commit 54b622d

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,14 @@ use {
348348
["on"] = { "order_by_name", nowait = false },
349349
["os"] = { "order_by_size", nowait = false },
350350
["ot"] = { "order_by_type", nowait = false },
351+
-- ['<key>'] = function(state) ... end,
351352
},
352353
fuzzy_finder_mappings = { -- define keymaps for filter popup window in fuzzy_finder_mode
353354
["<down>"] = "move_cursor_down",
354355
["<C-n>"] = "move_cursor_down",
355356
["<up>"] = "move_cursor_up",
356357
["<C-p>"] = "move_cursor_up",
358+
-- ['<key>'] = function(state, scroll_padding) ... end,
357359
},
358360
},
359361

Diff for: lua/neo-tree/sources/common/filters/init.lua

+10-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,16 @@ M.show_filter = function(state, search_as_you_type, keep_filter_on_submit)
213213

214214
local config = require("neo-tree").config
215215
for lhs, cmd_name in pairs(config.filesystem.window.fuzzy_finder_mappings) do
216-
local cmd = cmds[cmd_name]
217-
if cmd then
218-
input:map("i", lhs, utils.wrap(cmd, state, scroll_padding), { noremap = true })
216+
local t = type(cmd_name)
217+
if t == "string" then
218+
local cmd = cmds[cmd_name]
219+
if cmd then
220+
input:map("i", lhs, utils.wrap(cmd, state, scroll_padding), { noremap = true })
221+
else
222+
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
223+
end
224+
elseif t == "function" then
225+
input:map("i", lhs, utils.wrap(cmd_name, state, scroll_padding), { noremap = true })
219226
else
220227
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
221228
end

Diff for: lua/neo-tree/sources/filesystem/lib/filter.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,19 @@ M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode, use_fzy)
220220
if fuzzy_finder_mode then
221221
local config = require("neo-tree").config
222222
for lhs, cmd_name in pairs(config.filesystem.window.fuzzy_finder_mappings) do
223-
local cmd = cmds[cmd_name]
224-
if cmd then
225-
input:map("i", lhs, create_input_mapping_handle(cmd, state, scroll_padding), { noremap = true })
223+
local t = type(cmd_name)
224+
if t == "string" then
225+
local cmd = cmds[cmd_name]
226+
if cmd then
227+
input:map("i", lhs, create_input_mapping_handle(cmd, state, scroll_padding), { noremap = true })
228+
else
229+
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
230+
end
231+
elseif t == "function" then
232+
input:map("i", lhs, create_input_mapping_handle(cmd_name, state, scroll_padding),
233+
{ noremap = true })
226234
else
227-
log.warn(string.format('Invalid command in fuzzy_finder_mappings: %s = %s', lhs, cmd_name))
235+
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
228236
end
229237
end
230238
end

0 commit comments

Comments
 (0)