* refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class, WIP * refactor(#2826): singleton View class * refactor(#2826): View is an Explorer member * refactor(#2826): move autocmds to Explorer * refactor(#2826): API uses Explorer's View * refactor(#2826): move View into Explorer package * refactor(#2826): retain necessary view globals * refactor(#2826): move all winhl to appearance constants * refactor(#2826): add lifecycle logging to all Explorer members * refactor(#2826): fix bad cherry-pick * refactor(#2826): better enumerate_options function * refactor(#2826): add View.tab_line for debugging * refactor(#2826): default lifecycle log off * refactor(#2826): add experimental.multi_instance_debug, split globals out of view, move diagnostics to its own module * refactor(#2826): instrument View:get_winnr * refactor(#2826): instrument View:setup_tabpage * refactor(#2826): instrument View:set_current_win, View:prevent_buffer_override * refactor(#2826): instrument View:get_bufnr * refactor(#2826): track member bufnr -> winid with global * refactor(#2826): tidy experiment names and logs * vim: nvim-tree: track bufnr via buffer-update channel * vim: nvim-tree: more logging * vim: nvim-tree: revert: track bufnr via buffer-update channel * refactor(#2826): notify error on view winid and bufnr mismatches * refactor(#2826): notify error on view winid and bufnr mismatches * refactor(#2826): explorer init logging
44 lines
1007 B
Lua
44 lines
1007 B
Lua
local utils = require("nvim-tree.utils")
|
|
|
|
local DirectoryNode = require("nvim-tree.node.directory")
|
|
|
|
local M = {}
|
|
|
|
---@param should_close boolean|nil
|
|
---@return fun(node: Node): boolean|nil
|
|
function M.fn(should_close)
|
|
should_close = should_close or false
|
|
|
|
---@param node Node
|
|
return function(node)
|
|
local dir = node:as(DirectoryNode)
|
|
if dir then
|
|
dir = dir:last_group_node()
|
|
if should_close and dir.open then
|
|
dir.open = false
|
|
dir.explorer.renderer:draw()
|
|
return
|
|
end
|
|
end
|
|
|
|
local parent = (node:get_parent_of_group() or node).parent
|
|
|
|
if not parent or not parent.parent then
|
|
node.explorer.view:set_cursor({ 1, 0 })
|
|
return
|
|
end
|
|
|
|
local _, line = utils.find_node(parent.explorer.nodes, function(n)
|
|
return n.absolute_path == parent.absolute_path
|
|
end)
|
|
|
|
node.explorer.view:set_cursor({ line + 1, 0 })
|
|
if should_close then
|
|
parent.open = false
|
|
parent.explorer.renderer:draw()
|
|
end
|
|
end
|
|
end
|
|
|
|
return M
|