Skip to content
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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,13 @@ use {
["<c-x>"] = "clear_filter",
["[g"] = "prev_git_modified",
["]g"] = "next_git_modified",
}
},
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",
},
}
},
buffers = {
Expand Down
8 changes: 7 additions & 1 deletion lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ local config = {
["."] = "set_root",
["[g"] = "prev_git_modified",
["]g"] = "next_git_modified",
}
},
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",
},
},
async_directory_scan = "auto", -- "auto" means refreshes are async, but it's synchronous when called from the Neotree commands.
-- "always" means directory scans are always async.
Expand Down
37 changes: 25 additions & 12 deletions lua/neo-tree/sources/filesystem/lib/filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ local vim = vim
local Input = require("nui.input")
local event = require("nui.utils.autocmd").event
local fs = require("neo-tree.sources.filesystem")
local inputs = require("neo-tree.ui.inputs")
local popups = require("neo-tree.ui.popups")
local renderer = require("neo-tree.ui.renderer")
local utils = require("neo-tree.utils")
local log = require("neo-tree.log")
local manager = require("neo-tree.sources.manager")
local renderer = require("neo-tree.ui.renderer")

local M = {}

local cmds = {
move_cursor_down = function(state, scroll_padding)
renderer.focus_node(state, nil, true, 1, scroll_padding)
end,

move_cursor_up = function(state, scroll_padding)
renderer.focus_node(state, nil, true, -1, scroll_padding)
vim.cmd("redraw!")
end,
}

local function create_input_mapping_handle(cmd, state, scroll_padding)
return function()
cmd(state, scroll_padding)
end
end

M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode, use_fzy)
local popup_options
local winid = vim.api.nvim_get_current_win()
Expand Down Expand Up @@ -203,17 +218,15 @@ M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode, use_fzy)
end, { once = true })

if fuzzy_finder_mode then
local move_cursor_down = function()
renderer.focus_node(state, nil, true, 1, scroll_padding)
end
local move_cursor_up = function()
renderer.focus_node(state, nil, true, -1, scroll_padding)
vim.cmd("redraw!")
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 })
else
log.warn(string.format('Invalid command in fuzzy_finder_mappings: %s = %s', lhs, cmd_name))
end
end
input:map("i", "<down>", move_cursor_down, { noremap = true })
input:map("i", "<C-n>", move_cursor_down, { noremap = true })
input:map("i", "<up>", move_cursor_up, { noremap = true })
input:map("i", "<C-p>", move_cursor_up, { noremap = true })
end
end

Expand Down