From 5e900c2f29d1c9cb0dfe85ca2674ebcf7e25452b Mon Sep 17 00:00:00 2001 From: kiyan Date: Sun, 29 May 2022 11:40:06 +0200 Subject: [PATCH] refacto: tree explorer root should be absolute_path not cwd --- lua/nvim-tree.lua | 2 +- lua/nvim-tree/actions/movements.lua | 2 +- lua/nvim-tree/actions/reloaders.lua | 2 +- lua/nvim-tree/core.lua | 2 +- lua/nvim-tree/explorer/explore.lua | 4 ++-- lua/nvim-tree/explorer/init.lua | 4 ++-- lua/nvim-tree/explorer/reload.lua | 4 ++-- lua/nvim-tree/lib.lua | 2 +- lua/nvim-tree/live-filter.lua | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index e63426cc..2b4f9604 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -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 diff --git a/lua/nvim-tree/actions/movements.lua b/lua/nvim-tree/actions/movements.lua index cc683305..e21a9726 100644 --- a/lua/nvim-tree/actions/movements.lua +++ b/lua/nvim-tree/actions/movements.lua @@ -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 diff --git a/lua/nvim-tree/actions/reloaders.lua b/lua/nvim-tree/actions/reloaders.lua index c2aa7a5f..c2b403a6 100644 --- a/lua/nvim-tree/actions/reloaders.lua +++ b/lua/nvim-tree/actions/reloaders.lua @@ -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 diff --git a/lua/nvim-tree/core.lua b/lua/nvim-tree/core.lua index 7ee7eba6..faee0105 100644 --- a/lua/nvim-tree/core.lua +++ b/lua/nvim-tree/core.lua @@ -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() diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index b886485c..f4e1c904 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -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 diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index 0bd1e78d..980358b2 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -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 diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index 773e6fa5..4680f479 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -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 diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index f47941d3..99a51722 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -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 diff --git a/lua/nvim-tree/live-filter.lua b/lua/nvim-tree/live-filter.lua index 7fa8c5f0..d04ff34b 100644 --- a/lua/nvim-tree/live-filter.lua +++ b/lua/nvim-tree/live-filter.lua @@ -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