refacto: tree explorer root should be absolute_path not cwd

This commit is contained in:
kiyan 2022-05-29 11:40:06 +02:00
parent 3806653d75
commit 5e900c2f29
9 changed files with 12 additions and 12 deletions

View File

@ -102,7 +102,7 @@ local function update_base_dir_with_filepath(filepath, bufnr)
end
end
if not vim.startswith(filepath, core.get_explorer().cwd) then
if not vim.startswith(filepath, core.get_cwd()) then
change_dir.fn(vim.fn.fnamemodify(filepath, ":p:h"))
end
end

View File

@ -33,7 +33,7 @@ function M.parent_node(should_close)
local parent = node.parent
if not parent or parent.cwd then
if not parent or not parent.parent then
return view.set_cursor { 1, 0 }
end

View File

@ -18,7 +18,7 @@ local function refresh_nodes(node, projects)
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 project_root = git.get_project_root(parent_node.absolute_path)
local status = projects[project_root] or {}
for _, node in ipairs(parent_node.nodes) do
if node.nodes then

View File

@ -21,7 +21,7 @@ function M.get_explorer()
end
function M.get_cwd()
return TreeExplorer.cwd
return TreeExplorer.absolute_path
end
function M.get_nodes_starting_line()

View File

@ -59,7 +59,7 @@ local function get_dir_handle(cwd)
end
function M.explore(node, status)
local cwd = node.cwd or node.link_to or node.absolute_path
local cwd = node.link_to or node.absolute_path
local handle = get_dir_handle(cwd)
if not handle then
return
@ -67,7 +67,7 @@ function M.explore(node, status)
populate_children(handle, cwd, node, status)
local is_root = node.cwd ~= nil
local is_root = not node.parent
local child_folder_only = common.has_one_child_folder(node) and node.nodes[1]
if M.config.group_empty and not is_root and child_folder_only then
node.group_next = child_folder_only

View File

@ -13,7 +13,7 @@ Explorer.__index = Explorer
function Explorer.new(cwd)
cwd = uv.fs_realpath(cwd or uv.cwd())
local explorer = setmetatable({
cwd = cwd,
absolute_path = cwd,
nodes = {},
}, Explorer)
explorer:_load(explorer)
@ -21,7 +21,7 @@ function Explorer.new(cwd)
end
function Explorer:_load(node)
local cwd = node.cwd or node.link_to or node.absolute_path
local cwd = node.link_to or node.absolute_path
local git_statuses = git.load_project_status(cwd)
M.explore(node, git_statuses)
end

View File

@ -20,7 +20,7 @@ local function update_status(nodes_by_path, node_ignored, status)
end
function M.reload(node, status)
local cwd = node.cwd or node.link_to or node.absolute_path
local cwd = node.link_to or node.absolute_path
local handle = uv.fs_scandir(cwd)
if type(handle) == "string" then
api.nvim_err_writeln(handle)
@ -68,7 +68,7 @@ function M.reload(node, status)
end, node.nodes)
)
local is_root = node.cwd ~= nil
local is_root = not node.parent
local child_folder_only = common.has_one_child_folder(node) and node.nodes[1]
if M.config.group_empty and not is_root and child_folder_only then
node.group_next = child_folder_only

View File

@ -68,7 +68,7 @@ function M.set_target_win()
end
local function handle_buf_cwd(cwd)
if M.respect_buf_cwd and cwd ~= core.get_explorer().cwd then
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
require("nvim-tree.actions.change-dir").fn(cwd)
end
end

View File

@ -36,7 +36,7 @@ local function remove_overlay()
end
local function matches(node)
local path = node.cwd or node.absolute_path
local path = node.absolute_path
local name = vim.fn.fnamemodify(path, ":t")
return vim.regex(M.filter):match_str(name) ~= nil
end