committed by
GitHub
parent
3cc698b35b
commit
1fe32286db
@@ -3,7 +3,6 @@ local view = require "nvim-tree.view"
|
|||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local renderer = require "nvim-tree.renderer"
|
local renderer = require "nvim-tree.renderer"
|
||||||
local core = require "nvim-tree.core"
|
local core = require "nvim-tree.core"
|
||||||
local reload = require "nvim-tree.explorer.reload"
|
|
||||||
local Iterator = require "nvim-tree.iterators.node-iterator"
|
local Iterator = require "nvim-tree.iterators.node-iterator"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -30,10 +29,8 @@ function M.fn(path)
|
|||||||
|
|
||||||
local profile = log.profile_start("find file %s", path_real)
|
local profile = log.profile_start("find file %s", path_real)
|
||||||
|
|
||||||
-- we cannot wait for watchers to populate a new node
|
-- force a re-expand when the node is not in the tree
|
||||||
if utils.get_node_from_path(path_real) == nil then
|
local node_present = utils.get_node_from_path(path_real) ~= nil
|
||||||
reload.refresh_nodes_for_path(vim.fn.fnamemodify(path_real, ":h"))
|
|
||||||
end
|
|
||||||
|
|
||||||
local line = core.get_nodes_starting_line()
|
local line = core.get_nodes_starting_line()
|
||||||
|
|
||||||
@@ -60,7 +57,7 @@ function M.fn(path)
|
|||||||
if not node.group_next then
|
if not node.group_next then
|
||||||
node.open = true
|
node.open = true
|
||||||
end
|
end
|
||||||
if #node.nodes == 0 then
|
if #node.nodes == 0 or not node_present then
|
||||||
core.get_explorer():expand(node)
|
core.get_explorer():expand(node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ local live_filter = require "nvim-tree.live-filter"
|
|||||||
local git = require "nvim-tree.git"
|
local git = require "nvim-tree.git"
|
||||||
local log = require "nvim-tree.log"
|
local log = require "nvim-tree.log"
|
||||||
|
|
||||||
local NodeIterator = require "nvim-tree.iterators.node-iterator"
|
|
||||||
local Watcher = require "nvim-tree.watcher"
|
local Watcher = require "nvim-tree.watcher"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -178,44 +177,6 @@ function M.refresh_node(node, callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Refresh contents and git status for all nodes to a path: actual directory and links
|
|
||||||
---@param path string absolute path
|
|
||||||
function M.refresh_nodes_for_path(path)
|
|
||||||
local explorer = require("nvim-tree.core").get_explorer()
|
|
||||||
if not explorer then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local profile = log.profile_start("refresh_nodes_for_path %s", path)
|
|
||||||
|
|
||||||
-- avoids cycles
|
|
||||||
local absolute_paths_refreshed = {}
|
|
||||||
|
|
||||||
NodeIterator.builder({ explorer })
|
|
||||||
:hidden()
|
|
||||||
:recursor(function(node)
|
|
||||||
if node.group_next then
|
|
||||||
return { node.group_next }
|
|
||||||
end
|
|
||||||
if node.nodes then
|
|
||||||
return node.nodes
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
:applier(function(node)
|
|
||||||
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) == 1
|
|
||||||
local link_contains = node.link_to and path:find(node.link_to, 1, true) == 1
|
|
||||||
if abs_contains or link_contains then
|
|
||||||
if not absolute_paths_refreshed[node.absolute_path] then
|
|
||||||
absolute_paths_refreshed[node.absolute_path] = true
|
|
||||||
M.refresh_node(node)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
:iterate()
|
|
||||||
|
|
||||||
log.profile_end(profile)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
M.config = opts.renderer
|
M.config = opts.renderer
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user