Skip to content

feat: allow to pass function to fuzzy_finder_mappings #1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,14 @@ use {
["on"] = { "order_by_name", nowait = false },
["os"] = { "order_by_size", nowait = false },
["ot"] = { "order_by_type", nowait = false },
-- ['<key>'] = function(state) ... end,
},
fuzzy_finder_mappings = { -- define keymaps for filter popup window in fuzzy_finder_mode
["<down>"] = "move_cursor_down",
["<C-n>"] = "move_cursor_down",
["<up>"] = "move_cursor_up",
["<C-p>"] = "move_cursor_up",
-- ['<key>'] = function(state, scroll_padding) ... end,
},
},

Expand Down
13 changes: 10 additions & 3 deletions lua/neo-tree/sources/common/filters/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,16 @@ M.show_filter = function(state, search_as_you_type, keep_filter_on_submit)

local config = require("neo-tree").config
for lhs, cmd_name in pairs(config.filesystem.window.fuzzy_finder_mappings) do
local cmd = cmds[cmd_name]
if cmd then
input:map("i", lhs, utils.wrap(cmd, state, scroll_padding), { noremap = true })
local t = type(cmd_name)
if t == "string" then
local cmd = cmds[cmd_name]
if cmd then
input:map("i", lhs, utils.wrap(cmd, state, scroll_padding), { noremap = true })
else
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
end
elseif t == "function" then
input:map("i", lhs, utils.wrap(cmd_name, state, scroll_padding), { noremap = true })
else
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
end
Expand Down
16 changes: 12 additions & 4 deletions lua/neo-tree/sources/filesystem/lib/filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,19 @@ M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode, use_fzy)
if fuzzy_finder_mode then
local config = require("neo-tree").config
for lhs, cmd_name in pairs(config.filesystem.window.fuzzy_finder_mappings) do
local cmd = cmds[cmd_name]
if cmd then
input:map("i", lhs, create_input_mapping_handle(cmd, state, scroll_padding), { noremap = true })
local t = type(cmd_name)
if t == "string" then
local cmd = cmds[cmd_name]
if cmd then
input:map("i", lhs, create_input_mapping_handle(cmd, state, scroll_padding), { noremap = true })
else
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
end
elseif t == "function" then
input:map("i", lhs, create_input_mapping_handle(cmd_name, state, scroll_padding),
{ noremap = true })
else
log.warn(string.format('Invalid command in fuzzy_finder_mappings: %s = %s', lhs, cmd_name))
log.warn(string.format("Invalid command in fuzzy_finder_mappings: %s = %s", lhs, cmd_name))
end
end
end
Expand Down
Loading