chore: move refresh/reloaders into actions.reloaders
This commit is contained in:
@@ -108,7 +108,7 @@ local function do_paste(node, action_type, action_fn)
|
||||
end
|
||||
|
||||
clipboard[action_type] = {}
|
||||
return lib.refresh_tree()
|
||||
return require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
|
||||
local function do_cut(source, destination)
|
||||
|
||||
@@ -102,7 +102,7 @@ function M.fn(node)
|
||||
a.nvim_out_write(file..' was properly created\n')
|
||||
end
|
||||
events._dispatch_folder_created(file)
|
||||
lib.refresh_tree(function()
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer(function()
|
||||
focus_file(file)
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -69,7 +69,7 @@ local keypress_funcs = {
|
||||
toggle_ignored = lib.toggle_ignored,
|
||||
toggle_dotfiles = lib.toggle_dotfiles,
|
||||
toggle_help = lib.toggle_help,
|
||||
refresh = lib.refresh_tree,
|
||||
refresh = require'nvim-tree.actions.reloaders'.reload_explorer,
|
||||
first_sibling = require'nvim-tree.actions.movements'.sibling(-math.huge),
|
||||
last_sibling = require'nvim-tree.actions.movements'.sibling(math.huge),
|
||||
prev_sibling = require'nvim-tree.actions.movements'.sibling(-1),
|
||||
|
||||
68
lua/nvim-tree/actions/reloaders.lua
Normal file
68
lua/nvim-tree/actions/reloaders.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local git = require "nvim-tree.git"
|
||||
local diagnostics = require "nvim-tree.diagnostics"
|
||||
local view = require "nvim-tree.view"
|
||||
local explorer_module = require'nvim-tree.explorer'
|
||||
local get_explorer = function() return require "nvim-tree.lib".Tree end
|
||||
|
||||
local M = {}
|
||||
|
||||
local function refresh_nodes(node, projects)
|
||||
local project_root = git.get_project_root(node.absolute_path or node.cwd)
|
||||
explorer_module.refresh(node.nodes, node.absolute_path or node.cwd, node, projects[project_root] or {})
|
||||
for _, _node in ipairs(node.nodes) do
|
||||
if _node.nodes and _node.open then
|
||||
refresh_nodes(_node, projects)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.reload_node_status(parent_node, projects)
|
||||
local project_root = git.get_project_root(parent_node.absolute_path or parent_node.cwd)
|
||||
local status = projects[project_root] or {}
|
||||
for _, node in ipairs(parent_node.nodes) do
|
||||
if node.nodes then
|
||||
node.git_status = status.dirs and status.dirs[node.absolute_path]
|
||||
else
|
||||
node.git_status = status.files and status.files[node.absolute_path]
|
||||
end
|
||||
if node.nodes and #node.nodes > 0 then
|
||||
M.reload_node_status(node, projects)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local event_running = false
|
||||
function M.reload_explorer(callback)
|
||||
local Explorer = get_explorer()
|
||||
if event_running or not Explorer.cwd or vim.v.exiting ~= vim.NIL then
|
||||
return
|
||||
end
|
||||
event_running = true
|
||||
|
||||
git.reload(function(projects)
|
||||
refresh_nodes(Explorer, projects)
|
||||
if view.win_open() then
|
||||
require"nvim-tree.lib".redraw()
|
||||
if callback and type(callback) == 'function' then
|
||||
callback()
|
||||
end
|
||||
end
|
||||
diagnostics.update()
|
||||
event_running = false
|
||||
end)
|
||||
end
|
||||
|
||||
function M.reload_git()
|
||||
if not git.config.enable or event_running then
|
||||
return
|
||||
end
|
||||
event_running = true
|
||||
|
||||
git.reload(function(projects)
|
||||
M.reload_node_status(get_explorer(), projects)
|
||||
require"nvim-tree.lib".redraw()
|
||||
event_running = false
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -2,7 +2,6 @@ local a = vim.api
|
||||
local luv = vim.loop
|
||||
|
||||
local utils = require'nvim-tree.utils'
|
||||
local lib = require'nvim-tree.lib'
|
||||
local events = require'nvim-tree.events'
|
||||
|
||||
local M = {}
|
||||
@@ -72,7 +71,7 @@ function M.fn(node)
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
end
|
||||
lib.refresh_tree()
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ function M.fn(with_sub)
|
||||
a.nvim_out_write(node.absolute_path..' ➜ '..new_name..'\n')
|
||||
utils.rename_loaded_buffers(node.absolute_path, new_name)
|
||||
events._dispatch_node_renamed(abs_path, new_name)
|
||||
lib.refresh_tree()
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ local M = {
|
||||
}
|
||||
}
|
||||
|
||||
local lib = require'nvim-tree.lib'
|
||||
local utils = require'nvim-tree.utils'
|
||||
local events = require'nvim-tree.events'
|
||||
|
||||
@@ -64,13 +63,13 @@ function M.fn(node)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
trash_path(function()
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
lib.refresh_tree()
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end)
|
||||
else
|
||||
trash_path(function()
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
lib.refresh_tree()
|
||||
require'nvim-tree.actions.reloaders'.reload_explorer()
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user