* move last_group_node to DirectoryNode * move add BaseNode:as and more doc * revert parameter name changes * revert parameter name changes * add Class * move group methods into DN * tidy group methods * tidy group methods * tidy group methods * tidy group methods * parent is DirectoryNode * tidy expand all * BaseNode -> Node * move watcher to DirectoryNode * last_group_node is DirectoryNode only * simplify create-file * simplify parent * simplify collapse-all * simplify live-filter * style
56 lines
1.2 KiB
Lua
56 lines
1.2 KiB
Lua
local utils = require("nvim-tree.utils")
|
|
local core = require("nvim-tree.core")
|
|
local lib = require("nvim-tree.lib")
|
|
local Iterator = require("nvim-tree.iterators.node-iterator")
|
|
|
|
local DirectoryNode = require("nvim-tree.node.directory")
|
|
|
|
local M = {}
|
|
|
|
---@return fun(path: string): boolean
|
|
local function buf_match()
|
|
local buffer_paths = vim.tbl_map(function(buffer)
|
|
return vim.api.nvim_buf_get_name(buffer)
|
|
end, vim.api.nvim_list_bufs())
|
|
|
|
return function(path)
|
|
for _, buffer_path in ipairs(buffer_paths) do
|
|
local matches = utils.str_find(buffer_path, path)
|
|
if matches then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
end
|
|
|
|
---@param keep_buffers boolean
|
|
function M.fn(keep_buffers)
|
|
local node = lib.get_node_at_cursor()
|
|
local explorer = core.get_explorer()
|
|
|
|
if explorer == nil then
|
|
return
|
|
end
|
|
|
|
local matches = buf_match()
|
|
|
|
Iterator.builder(explorer.nodes)
|
|
:hidden()
|
|
:applier(function(n)
|
|
local dir = n:as(DirectoryNode)
|
|
if dir then
|
|
dir.open = keep_buffers and matches(dir.absolute_path)
|
|
end
|
|
end)
|
|
:recursor(function(n)
|
|
return n.group_next and { n.group_next } or n.nodes
|
|
end)
|
|
:iterate()
|
|
|
|
explorer.renderer:draw()
|
|
utils.focus_node_or_parent(node)
|
|
end
|
|
|
|
return M
|