refacto: ubiquitous language renaming

BREAKING
- rename all 'entry' to 'node' or '_node' if shadowing
- rename all 'entries' to 'nodes'
This commit is contained in:
kiyan
2022-02-05 18:10:09 +01:00
parent 10b4a97f7f
commit 4a9e53143b
13 changed files with 113 additions and 113 deletions

View File

@@ -6,13 +6,13 @@ function M.fn()
if node.open then if node.open then
node.open = false node.open = false
end end
if node.entries then if node.nodes then
iter(node.entries) iter(node.nodes)
end end
end end
end end
iter(require'nvim-tree.lib'.Tree.entries) iter(require'nvim-tree.lib'.Tree.nodes)
require'nvim-tree.lib'.redraw() require'nvim-tree.lib'.redraw()
end end

View File

@@ -68,8 +68,8 @@ end
local function add_to_clipboard(node, clip) local function add_to_clipboard(node, clip)
if node.name == '..' then return end if node.name == '..' then return end
for idx, entry in ipairs(clip) do for idx, _node in ipairs(clip) do
if entry.absolute_path == node.absolute_path then if _node.absolute_path == node.absolute_path then
table.remove(clip, idx) table.remove(clip, idx)
return a.nvim_out_write(node.absolute_path..' removed to clipboard.\n') return a.nvim_out_write(node.absolute_path..' removed to clipboard.\n')
end end
@@ -102,9 +102,9 @@ local function do_paste(node, action_type, action_fn)
destination = vim.fn.fnamemodify(destination, ':p:h:h') destination = vim.fn.fnamemodify(destination, ':p:h:h')
end end
for _, entry in ipairs(clip) do for _, _node in ipairs(clip) do
local dest = utils.path_join({destination, entry.name }) local dest = utils.path_join({destination, _node.name })
do_single_paste(entry.absolute_path, dest, action_type, action_fn) do_single_paste(_node.absolute_path, dest, action_type, action_fn)
end end
clipboard[action_type] = {} clipboard[action_type] = {}
@@ -159,13 +159,13 @@ end
function M.copy_path(node) function M.copy_path(node)
local absolute_path = node.absolute_path local absolute_path = node.absolute_path
local relative_path = utils.path_relative(absolute_path, lib.Tree.cwd) local relative_path = utils.path_relative(absolute_path, lib.Tree.cwd)
local content = node.entries ~= nil and utils.path_add_trailing(relative_path) or relative_path local content = node.nodes ~= nil and utils.path_add_trailing(relative_path) or relative_path
return copy_to_clipboard(content) return copy_to_clipboard(content)
end end
function M.copy_absolute_path(node) function M.copy_absolute_path(node)
local absolute_path = node.absolute_path local absolute_path = node.absolute_path
local content = node.entries ~= nil and utils.path_add_trailing(absolute_path) or absolute_path local content = node.nodes ~= nil and utils.path_add_trailing(absolute_path) or absolute_path
return copy_to_clipboard(content) return copy_to_clipboard(content)
end end

View File

@@ -9,7 +9,7 @@ local M = {}
local function focus_file(file) local function focus_file(file)
local _, i = utils.find_node( local _, i = utils.find_node(
lib.Tree.entries, lib.Tree.nodes,
function(node) return node.absolute_path == file end function(node) return node.absolute_path == file end
) )
require'nvim-tree.view'.set_cursor({i+1, 1}) require'nvim-tree.view'.set_cursor({i+1, 1})
@@ -33,7 +33,7 @@ local function create_file(file)
events._dispatch_file_created(file) events._dispatch_file_created(file)
end end
local function get_num_entries(iter) local function get_num_nodes(iter)
local i = 0 local i = 0
for _ in iter do for _ in iter do
i = i + 1 i = i + 1
@@ -43,7 +43,7 @@ end
local function get_containing_folder(node) local function get_containing_folder(node)
local is_open = vim.g.nvim_tree_create_in_closed_folder == 1 or node.open local is_open = vim.g.nvim_tree_create_in_closed_folder == 1 or node.open
if node.entries ~= nil and is_open then if node.nodes ~= nil and is_open then
return utils.path_add_trailing(node.absolute_path) return utils.path_add_trailing(node.absolute_path)
end end
local node_name_size = #(node.name or '') local node_name_size = #(node.name or '')
@@ -62,7 +62,7 @@ function M.fn(node)
if node.name == '..' then if node.name == '..' then
node = { node = {
absolute_path = lib.Tree.cwd, absolute_path = lib.Tree.cwd,
entries = lib.Tree.entries, nodes = lib.Tree.nodes,
open = true, open = true,
} }
end end
@@ -72,12 +72,12 @@ function M.fn(node)
if not file then return end if not file then return end
-- create a folder for each path element if the folder does not exist -- create a folder for each path element if the folder does not exist
-- if the answer ends with a /, create a file for the last entry -- if the answer ends with a /, create a file for the last path element
local is_last_path_file = not file:match(utils.path_separator..'$') local is_last_path_file = not file:match(utils.path_separator..'$')
local path_to_create = '' local path_to_create = ''
local idx = 0 local idx = 0
local num_entries = get_num_entries(utils.path_split(utils.path_remove_trailing(file))) local num_nodes = get_num_nodes(utils.path_split(utils.path_remove_trailing(file)))
local is_error = false local is_error = false
for path in utils.path_split(file) do for path in utils.path_split(file) do
idx = idx + 1 idx = idx + 1
@@ -87,7 +87,7 @@ function M.fn(node)
else else
path_to_create = utils.path_join({path_to_create, p}) path_to_create = utils.path_join({path_to_create, p})
end end
if is_last_path_file and idx == num_entries then if is_last_path_file and idx == num_nodes then
create_file(path_to_create) create_file(path_to_create)
elseif not utils.file_exists(path_to_create) then elseif not utils.file_exists(path_to_create) then
local success = uv.fs_mkdir(path_to_create, 493) local success = uv.fs_mkdir(path_to_create, 493)

View File

@@ -82,7 +82,7 @@ local keypress_funcs = {
if node.name == '..' then if node.name == '..' then
return return
end end
if node.entries ~= nil then if node.nodes ~= nil then
return lib.expand_or_collapse(node) return lib.expand_or_collapse(node)
end end
return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path) return require'nvim-tree.actions.open-file'.fn('preview', node.absolute_path)
@@ -107,15 +107,15 @@ function M.on_keypress(action)
if node.name == ".." then if node.name == ".." then
return require'nvim-tree.actions.change-dir'.fn("..") return require'nvim-tree.actions.change-dir'.fn("..")
elseif action == "cd" and node.entries ~= nil then elseif action == "cd" and node.nodes ~= nil then
return require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path) return require'nvim-tree.actions.change-dir'.fn(lib.get_last_group_node(node).absolute_path)
elseif action == "cd" then elseif action == "cd" then
return return
end end
if node.link_to and not node.entries then if node.link_to and not node.nodes then
require'nvim-tree.actions.open-file'.fn(action, node.link_to) require'nvim-tree.actions.open-file'.fn(action, node.link_to)
elseif node.entries ~= nil then elseif node.nodes ~= nil then
lib.expand_or_collapse(node) lib.expand_or_collapse(node)
else else
require'nvim-tree.actions.open-file'.fn(action, node.absolute_path) require'nvim-tree.actions.open-file'.fn(action, node.absolute_path)

View File

@@ -13,16 +13,16 @@ local function get_line_from_node(node, find_parent)
end end
local line = 2 local line = 2
local function iter(entries, recursive) local function iter(nodes, recursive)
for _, entry in ipairs(entries) do for _, _node in ipairs(nodes) do
local n = lib().get_last_group_node(entry) local n = lib().get_last_group_node(_node)
if node_path == n.absolute_path then if node_path == n.absolute_path then
return line, entry return line, _node
end end
line = line + 1 line = line + 1
if entry.open == true and recursive then if _node.open == true and recursive then
local _, child = iter(entry.entries, recursive) local _, child = iter(_node.nodes, recursive)
if child ~= nil then return line, child end if child ~= nil then return line, child end
end end
end end
@@ -42,7 +42,7 @@ function M.parent_node(node, should_close)
node.open = false node.open = false
altered_tree = true altered_tree = true
else else
local line, parent = iter(lib().Tree.entries, true) local line, parent = iter(lib().Tree.nodes, true)
if parent == nil then if parent == nil then
line = 1 line = 1
elseif should_close then elseif should_close then
@@ -69,9 +69,9 @@ function M.sibling(direction)
local line = 0 local line = 0
local parent, _ local parent, _
-- Check if current node is already at root entries -- Check if current node is already at root nodes
for index, entry in ipairs(lib().Tree.entries) do for index, _node in ipairs(lib().Tree.nodes) do
if node_path == entry.absolute_path then if node_path == _node.absolute_path then
line = index line = index
end end
end end
@@ -79,9 +79,9 @@ function M.sibling(direction)
if line > 0 then if line > 0 then
parent = lib().Tree parent = lib().Tree
else else
_, parent = iter(lib().Tree.entries, true) _, parent = iter(lib().Tree.nodes, true)
if parent ~= nil and #parent.entries > 1 then if parent ~= nil and #parent.nodes > 1 then
line, _ = get_line_from_node(node)(parent.entries) line, _ = get_line_from_node(node)(parent.nodes)
end end
-- Ignore parent line count -- Ignore parent line count
@@ -91,12 +91,12 @@ function M.sibling(direction)
local index = line + direction local index = line + direction
if index < 1 then if index < 1 then
index = 1 index = 1
elseif index > #parent.entries then elseif index > #parent.nodes then
index = #parent.entries index = #parent.nodes
end end
local target_node = parent.entries[index] local target_node = parent.nodes[index]
line, _ = get_line_from_node(target_node)(lib().Tree.entries, true) line, _ = get_line_from_node(target_node)(lib().Tree.nodes, true)
view.set_cursor({line, 0}) view.set_cursor({line, 0})
end end
end end

View File

@@ -58,7 +58,7 @@ function M.fn(node)
local ans = utils.get_user_input_char() local ans = utils.get_user_input_char()
utils.clear_prompt() utils.clear_prompt()
if ans:match('^y') then if ans:match('^y') then
if node.entries ~= nil and not node.link_to then if node.nodes ~= nil and not node.link_to then
local success = remove_dir(node.absolute_path) local success = remove_dir(node.absolute_path)
if not success then if not success then
return a.nvim_err_writeln('Could not remove '..node.name) return a.nvim_err_writeln('Could not remove '..node.name)

View File

@@ -61,7 +61,7 @@ function M.fn(node)
-- trashing -- trashing
if is_confirmed then if is_confirmed then
if node.entries ~= nil and not node.link_to then if node.nodes ~= nil and not node.link_to then
trash_path(function() trash_path(function()
events._dispatch_folder_removed(node.absolute_path) events._dispatch_folder_removed(node.absolute_path)
lib.refresh_tree() lib.refresh_tree()

View File

@@ -111,7 +111,7 @@ function M.update()
buffer_severity = from_nvim_lsp() buffer_severity = from_nvim_lsp()
end end
local nodes = require'nvim-tree.lib'.Tree.entries local nodes = require'nvim-tree.lib'.Tree.nodes
if #signs then if #signs then
vim.fn.sign_unplacelist(vim.tbl_map(function(sign) vim.fn.sign_unplacelist(vim.tbl_map(function(sign)
return { return {

View File

@@ -29,7 +29,7 @@ local function dir_new(cwd, name, status, parent_ignored)
open = false, open = false,
group_next = nil, -- If node is grouped, this points to the next child dir/link node group_next = nil, -- If node is grouped, this points to the next child dir/link node
has_children = has_children, has_children = has_children,
entries = {}, nodes = {},
git_status = parent_ignored and '!!' or (status.dirs and status.dirs[absolute_path]) or (status.files and status.files[absolute_path]), git_status = parent_ignored and '!!' or (status.dirs and status.dirs[absolute_path]) or (status.files and status.files[absolute_path]),
} }
end end
@@ -62,10 +62,10 @@ local function link_new(cwd, name, status, parent_ignored)
local absolute_path = utils.path_join({ cwd, name }) local absolute_path = utils.path_join({ cwd, name })
local link_to = luv.fs_realpath(absolute_path) local link_to = luv.fs_realpath(absolute_path)
local stat = luv.fs_stat(absolute_path) local stat = luv.fs_stat(absolute_path)
local open, entries local open, nodes
if (link_to ~= nil) and luv.fs_stat(link_to).type == 'directory' then if (link_to ~= nil) and luv.fs_stat(link_to).type == 'directory' then
open = false open = false
entries = {} nodes = {}
end end
local last_modified = 0 local last_modified = 0
@@ -80,7 +80,7 @@ local function link_new(cwd, name, status, parent_ignored)
last_modified = last_modified, last_modified = last_modified,
open = open, open = open,
group_next = nil, -- If node is grouped, this points to the next child dir/link node group_next = nil, -- If node is grouped, this points to the next child dir/link node
entries = entries, nodes = nodes,
git_status = parent_ignored and '!!' or status.files and status.files[absolute_path], git_status = parent_ignored and '!!' or status.files and status.files[absolute_path],
} }
end end
@@ -108,9 +108,9 @@ local function node_comparator(a, b)
if not (a and b) then if not (a and b) then
return true return true
end end
if a.entries and not b.entries then if a.nodes and not b.nodes then
return true return true
elseif not a.entries and b.entries then elseif not a.nodes and b.nodes then
return false return false
end end
@@ -123,8 +123,8 @@ end
local function should_ignore(path) local function should_ignore(path)
local basename = utils.path_basename(path) local basename = utils.path_basename(path)
for _, entry in ipairs(M.exclude_list) do for _, node in ipairs(M.exclude_list) do
if path:match(entry) then if path:match(node) then
return false return false
end end
end end
@@ -166,28 +166,28 @@ function M.refresh(nodes, cwd, parent_node, status)
return return
end end
local named_entries = {} local named_nodes = {}
local cached_entries = {} local cached_nodes = {}
local entries_idx = {} local nodes_idx = {}
for i, node in ipairs(nodes) do for i, node in ipairs(nodes) do
node.git_status = (parent_node and parent_node.git_status == '!!' and '!!') node.git_status = (parent_node and parent_node.git_status == '!!' and '!!')
or (status.files and status.files[node.absolute_path]) or (status.files and status.files[node.absolute_path])
or (status.dirs and status.dirs[node.absolute_path]) or (status.dirs and status.dirs[node.absolute_path])
cached_entries[i] = node.name cached_nodes[i] = node.name
entries_idx[node.name] = i nodes_idx[node.name] = i
named_entries[node.name] = node named_nodes[node.name] = node
end end
local dirs = {} local dirs = {}
local links = {} local links = {}
local files = {} local files = {}
local new_entries = {} local new_nodes = {}
local num_new_entries = 0 local num_new_nodes = 0
while true do while true do
local name, t = luv.fs_scandir_next(handle) local name, t = luv.fs_scandir_next(handle)
if not name then break end if not name then break end
num_new_entries = num_new_entries + 1 num_new_nodes = num_new_nodes + 1
local abs = utils.path_join({cwd, name}) local abs = utils.path_join({cwd, name})
if not should_ignore(abs) and not should_ignore_git(abs, status.files) then if not should_ignore(abs) and not should_ignore_git(abs, status.files) then
@@ -198,13 +198,13 @@ function M.refresh(nodes, cwd, parent_node, status)
if t == 'directory' then if t == 'directory' then
table.insert(dirs, name) table.insert(dirs, name)
new_entries[name] = true new_nodes[name] = true
elseif t == 'file' then elseif t == 'file' then
table.insert(files, name) table.insert(files, name)
new_entries[name] = true new_nodes[name] = true
elseif t == 'link' then elseif t == 'link' then
table.insert(links, name) table.insert(links, name)
new_entries[name] = true new_nodes[name] = true
end end
end end
end end
@@ -213,11 +213,11 @@ function M.refresh(nodes, cwd, parent_node, status)
local next_node = parent_node.group_next local next_node = parent_node.group_next
if next_node then if next_node then
next_node.open = parent_node.open next_node.open = parent_node.open
if num_new_entries ~= 1 or not new_entries[next_node.name] then if num_new_nodes ~= 1 or not new_nodes[next_node.name] then
-- dir is no longer only containing a group dir, or group dir has been removed -- dir is no longer only containing a group dir, or group dir has been removed
-- either way: sever the group link on current dir -- either way: sever the group link on current dir
parent_node.group_next = nil parent_node.group_next = nil
named_entries[next_node.name] = next_node named_nodes[next_node.name] = next_node
else else
M.refresh(nodes, next_node.absolute_path, next_node, status) M.refresh(nodes, next_node.absolute_path, next_node, status)
return return
@@ -225,18 +225,18 @@ function M.refresh(nodes, cwd, parent_node, status)
end end
local idx = 1 local idx = 1
for _, name in ipairs(cached_entries) do for _, name in ipairs(cached_nodes) do
local node = named_entries[name] local node = named_nodes[name]
if node and node.link_to then if node and node.link_to then
-- If the link has been modified: remove it in case the link target has changed. -- If the link has been modified: remove it in case the link target has changed.
local stat = luv.fs_stat(node.absolute_path) local stat = luv.fs_stat(node.absolute_path)
if stat and node.last_modified ~= stat.mtime.sec then if stat and node.last_modified ~= stat.mtime.sec then
new_entries[name] = nil new_nodes[name] = nil
named_entries[name] = nil named_nodes[name] = nil
end end
end end
if not new_entries[name] then if not new_nodes[name] then
table.remove(nodes, idx) table.remove(nodes, idx)
else else
idx = idx + 1 idx = idx + 1
@@ -244,28 +244,28 @@ function M.refresh(nodes, cwd, parent_node, status)
end end
local all = { local all = {
{ entries = dirs, fn = dir_new, check = function(_, abs) return luv.fs_access(abs, 'R') end }, { nodes = dirs, fn = dir_new, check = function(_, abs) return luv.fs_access(abs, 'R') end },
{ entries = links, fn = link_new, check = function(name) return name ~= nil end }, { nodes = links, fn = link_new, check = function(name) return name ~= nil end },
{ entries = files, fn = file_new, check = function() return true end } { nodes = files, fn = file_new, check = function() return true end }
} }
local prev = nil local prev = nil
local change_prev local change_prev
local new_nodes_added = false local new_nodes_added = false
for _, e in ipairs(all) do for _, e in ipairs(all) do
for _, name in ipairs(e.entries) do for _, name in ipairs(e.nodes) do
change_prev = true change_prev = true
if not named_entries[name] then if not named_nodes[name] then
local n = e.fn(cwd, name, status) local n = e.fn(cwd, name, status)
if e.check(n.link_to, n.absolute_path) then if e.check(n.link_to, n.absolute_path) then
new_nodes_added = true new_nodes_added = true
idx = 1 idx = 1
if prev then if prev then
idx = entries_idx[prev] + 1 idx = nodes_idx[prev] + 1
end end
table.insert(nodes, idx, n) table.insert(nodes, idx, n)
entries_idx[name] = idx nodes_idx[name] = idx
cached_entries[idx] = name cached_nodes[idx] = name
else else
change_prev = false change_prev = false
end end
@@ -285,7 +285,7 @@ function M.refresh(nodes, cwd, parent_node, status)
end end
end end
function M.explore(entries, cwd, parent_node, status) function M.explore(nodes, cwd, parent_node, status)
local handle = luv.fs_scandir(cwd) local handle = luv.fs_scandir(cwd)
if type(handle) == 'string' then if type(handle) == 'string' then
api.nvim_err_writeln(handle) api.nvim_err_writeln(handle)
@@ -327,7 +327,7 @@ function M.explore(entries, cwd, parent_node, status)
if luv.fs_access(child_node.absolute_path, 'R') then if luv.fs_access(child_node.absolute_path, 'R') then
parent_node.group_next = child_node parent_node.group_next = child_node
child_node.git_status = parent_node.git_status child_node.git_status = parent_node.git_status
M.explore(entries, child_node.absolute_path, child_node, status) M.explore(nodes, child_node.absolute_path, child_node, status)
return return
end end
end end
@@ -336,23 +336,23 @@ function M.explore(entries, cwd, parent_node, status)
for _, dirname in ipairs(dirs) do for _, dirname in ipairs(dirs) do
local dir = dir_new(cwd, dirname, status, parent_node_ignored) local dir = dir_new(cwd, dirname, status, parent_node_ignored)
if luv.fs_access(dir.absolute_path, 'R') then if luv.fs_access(dir.absolute_path, 'R') then
table.insert(entries, dir) table.insert(nodes, dir)
end end
end end
for _, linkname in ipairs(links) do for _, linkname in ipairs(links) do
local link = link_new(cwd, linkname, status, parent_node_ignored) local link = link_new(cwd, linkname, status, parent_node_ignored)
if link.link_to ~= nil then if link.link_to ~= nil then
table.insert(entries, link) table.insert(nodes, link)
end end
end end
for _, filename in ipairs(files) do for _, filename in ipairs(files) do
local file = file_new(cwd, filename, status, parent_node_ignored) local file = file_new(cwd, filename, status, parent_node_ignored)
table.insert(entries, file) table.insert(nodes, file)
end end
utils.merge_sort(entries, node_comparator) utils.merge_sort(nodes, node_comparator)
end end
function M.setup(opts) function M.setup(opts)
@@ -366,8 +366,8 @@ function M.setup(opts)
local custom_filter = opts.filters.custom local custom_filter = opts.filters.custom
if custom_filter and #custom_filter > 0 then if custom_filter and #custom_filter > 0 then
for _, entry in pairs(custom_filter) do for _, filter_name in pairs(custom_filter) do
M.ignore_list[entry] = true M.ignore_list[filter_name] = true
end end
end end
end end

View File

@@ -14,7 +14,7 @@ local first_init_done = false
local M = {} local M = {}
M.Tree = { M.Tree = {
entries = {}, nodes = {},
cwd = nil, cwd = nil,
target_winid = nil, target_winid = nil,
} }
@@ -27,14 +27,14 @@ local function load_children(cwd, children, parent)
end end
function M.init(with_open, foldername) function M.init(with_open, foldername)
M.Tree.entries = {} M.Tree.nodes = {}
M.Tree.cwd = foldername or luv.cwd() M.Tree.cwd = foldername or luv.cwd()
if with_open then if with_open then
M.open() M.open()
end end
load_children(M.Tree.cwd, M.Tree.entries) load_children(M.Tree.cwd, M.Tree.nodes)
if not first_init_done then if not first_init_done then
events._dispatch_ready() events._dispatch_ready()
@@ -48,14 +48,14 @@ end
local function get_node_at_line(line) local function get_node_at_line(line)
local index = view.View.hide_root_folder and 1 or 2 local index = view.View.hide_root_folder and 1 or 2
local function iter(entries) local function iter(nodes)
for _, node in ipairs(entries) do for _, node in ipairs(nodes) do
if index == line then if index == line then
return node return node
end end
index = index + 1 index = index + 1
if node.open == true then if node.open == true then
local child = iter(node.entries) local child = iter(node.nodes)
if child ~= nil then return child end if child ~= nil then return child end
end end
end end
@@ -83,7 +83,7 @@ function M.get_node_at_cursor()
if M.Tree.cwd == "/" then if M.Tree.cwd == "/" then
line = line + 1 line = line + 1
end end
return get_node_at_line(line)(M.Tree.entries) return get_node_at_line(line)(M.Tree.nodes)
end end
end end
@@ -99,10 +99,10 @@ end
function M.expand_or_collapse(node) function M.expand_or_collapse(node)
node.open = not node.open node.open = not node.open
if node.has_children then node.has_children = false end if node.has_children then node.has_children = false end
if #node.entries == 0 then if #node.nodes == 0 then
load_children( load_children(
node.link_to or node.absolute_path, node.link_to or node.absolute_path,
node.entries, node.nodes,
node node
) )
else else
@@ -114,10 +114,10 @@ end
local function refresh_nodes(node, projects) local function refresh_nodes(node, projects)
local project_root = git.get_project_root(node.absolute_path or node.cwd) local project_root = git.get_project_root(node.absolute_path or node.cwd)
explorer.refresh(node.entries, node.absolute_path or node.cwd, node, projects[project_root] or {}) explorer.refresh(node.nodes, node.absolute_path or node.cwd, node, projects[project_root] or {})
for _, entry in ipairs(node.entries) do for _, _node in ipairs(node.nodes) do
if entry.entries and entry.open then if _node.nodes and _node.open then
refresh_nodes(entry, projects) refresh_nodes(_node, projects)
end end
end end
end end
@@ -145,13 +145,13 @@ end
local function reload_node_status(parent_node, projects) local function 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 or parent_node.cwd)
local status = projects[project_root] or {} local status = projects[project_root] or {}
for _, node in ipairs(parent_node.entries) do for _, node in ipairs(parent_node.nodes) do
if node.entries then if node.nodes then
node.git_status = status.dirs and status.dirs[node.absolute_path] node.git_status = status.dirs and status.dirs[node.absolute_path]
else else
node.git_status = status.files and status.files[node.absolute_path] node.git_status = status.files and status.files[node.absolute_path]
end end
if node.entries and #node.entries > 0 then if node.nodes and #node.nodes > 0 then
reload_node_status(node, projects) reload_node_status(node, projects)
end end
end end
@@ -190,9 +190,9 @@ function M.set_index_and_redraw(fname)
local path_matches = utils.str_find(fname, node.absolute_path..utils.path_separator) local path_matches = utils.str_find(fname, node.absolute_path..utils.path_separator)
if path_matches then if path_matches then
if #node.entries == 0 then if #node.nodes == 0 then
node.open = true node.open = true
explorer.explore(node.entries, node.absolute_path, node, {}) explorer.explore(node.nodes, node.absolute_path, node, {})
git.load_project_status(node.absolute_path, function(status) git.load_project_status(node.absolute_path, function(status)
if status.dirs or status.files then if status.dirs or status.files then
reload_node_status(node, git.projects) reload_node_status(node, git.projects)
@@ -204,16 +204,16 @@ function M.set_index_and_redraw(fname)
node.open = true node.open = true
tree_altered = true tree_altered = true
end end
if iterate_nodes(node.entries) ~= nil then if iterate_nodes(node.nodes) ~= nil then
return i return i
end end
elseif node.open == true then elseif node.open == true then
iterate_nodes(node.entries) iterate_nodes(node.nodes)
end end
end end
end end
local index = iterate_nodes(M.Tree.entries) local index = iterate_nodes(M.Tree.nodes)
if tree_altered then if tree_altered then
M.redraw() M.redraw()
end end

View File

@@ -284,7 +284,7 @@ local function update_draw_data(tree, depth, markers)
index = 1 index = 1
end end
for idx, node in ipairs(tree.entries) do for idx, node in ipairs(tree.nodes) do
local padding = _padding.get_padding(depth, idx, tree, node, markers) local padding = _padding.get_padding(depth, idx, tree, node, markers)
local offset = string.len(padding) local offset = string.len(padding)
if depth > 0 then if depth > 0 then
@@ -293,8 +293,8 @@ local function update_draw_data(tree, depth, markers)
local git_hl = get_git_hl(node) local git_hl = get_git_hl(node)
if node.entries then if node.nodes then
local has_children = #node.entries ~= 0 or node.has_children local has_children = #node.nodes ~= 0 or node.has_children
local icon = get_folder_icon(node.open, node.link_to ~= nil, has_children) local icon = get_folder_icon(node.open, node.link_to ~= nil, has_children)
local git_icon = get_git_icons(node, index, offset, #icon) or "" local git_icon = get_git_icons(node, index, offset, #icon) or ""
-- INFO: this is mandatory in order to keep gui attributes (bold/italics) -- INFO: this is mandatory in order to keep gui attributes (bold/italics)

View File

@@ -6,7 +6,7 @@ end
local function get_padding_arrows(icon_state) local function get_padding_arrows(icon_state)
return function(depth, _, _, node) return function(depth, _, _, node)
if node.entries then if node.nodes then
local icon = icon_state.icons.folder_icons[node.open and 'arrow_open' or 'arrow_closed'] local icon = icon_state.icons.folder_icons[node.open and 'arrow_open' or 'arrow_closed']
return string.rep(' ', depth - 2)..icon..' ' return string.rep(' ', depth - 2)..icon..' '
end end
@@ -18,9 +18,9 @@ local function get_padding_indent_markers(depth, idx, tree, _, markers)
local padding = "" local padding = ""
if depth ~= 0 then if depth ~= 0 then
local rdepth = depth/2 local rdepth = depth/2
markers[rdepth] = idx ~= #tree.entries markers[rdepth] = idx ~= #tree.nodes
for i=1,rdepth do for i=1,rdepth do
if idx == #tree.entries and i == rdepth then if idx == #tree.nodes and i == rdepth then
padding = padding..'' padding = padding..''
elseif markers[i] then elseif markers[i] then
padding = padding..'' padding = padding..''

View File

@@ -90,8 +90,8 @@ function M.find_node(_nodes, _fn)
local i = 1 local i = 1
for _, node in ipairs(nodes) do for _, node in ipairs(nodes) do
if fn(node) then return node, i end if fn(node) then return node, i end
if node.open and #node.entries > 0 then if node.open and #node.nodes > 0 then
local n, idx = iter(node.entries, fn) local n, idx = iter(node.nodes, fn)
i = i + idx i = i + idx
if n then return n, i end if n then return n, i end
else else