neo-tree.nvim
neo-tree.nvim copied to clipboard
Clear filter on file opened after `filter_on_submit`
I assigned a mapping for filter_on_submit but I'd like it so that after opening a file in the filtered results tree, the filter will be cleared.
I already have a file_opened event handler like so (closes the tree on open):
{
event = "file_opened",
handler = function()
require("neo-tree.command").execute({ action = "close" })
end,
}
I tried to add require("neo-tree.command").execute({ action = "clear_filter" }) on the same function but it doesn't seem to work.
Here is an example of how to do that with a specific mapping:
https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes#open-and-clear-search
You can also just extract the clear filter part out to put in your event handler:
local state = require("neo-tree.sources.manager").get_state("filesystem")
local cmds = require("neo-tree.sources.filesystem.commands")
cmds.clear_filter(state)
Hmm that seems to make it work, but it looks like calling cmds.clear_filter() also opens up the tree. So it doesn't work well in my file_opened event handler such that the tree closes on file open but instantly opens again (due to clear_filter() it seems).
Hmm that seems to make it work, but it looks like calling
cmds.clear_filter()also opens up the tree. So it doesn't work well in myfile_openedevent handler such that the tree closes on file open but instantly opens again (due toclear_filter()it seems).
cmds.clear_filter() calls fs.reset_search(state, true) where the second parameter is refresh. I changed the solution to the following and it won't open again:
local state = require("neo-tree.sources.manager").get_state("filesystem")
local fs = require("neo-tree.sources.filesystem")
fs.reset_search(state, false)