refacto: ubiquitous language renaming
BREAKING - rename all 'entry' to 'node' or '_node' if shadowing - rename all 'entries' to 'nodes'
This commit is contained in:
parent
10b4a97f7f
commit
4a9e53143b
@ -6,13 +6,13 @@ function M.fn()
|
||||
if node.open then
|
||||
node.open = false
|
||||
end
|
||||
if node.entries then
|
||||
iter(node.entries)
|
||||
if node.nodes then
|
||||
iter(node.nodes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
iter(require'nvim-tree.lib'.Tree.entries)
|
||||
iter(require'nvim-tree.lib'.Tree.nodes)
|
||||
require'nvim-tree.lib'.redraw()
|
||||
end
|
||||
|
||||
|
||||
@ -68,8 +68,8 @@ end
|
||||
local function add_to_clipboard(node, clip)
|
||||
if node.name == '..' then return end
|
||||
|
||||
for idx, entry in ipairs(clip) do
|
||||
if entry.absolute_path == node.absolute_path then
|
||||
for idx, _node in ipairs(clip) do
|
||||
if _node.absolute_path == node.absolute_path then
|
||||
table.remove(clip, idx)
|
||||
return a.nvim_out_write(node.absolute_path..' removed to clipboard.\n')
|
||||
end
|
||||
@ -102,9 +102,9 @@ local function do_paste(node, action_type, action_fn)
|
||||
destination = vim.fn.fnamemodify(destination, ':p:h:h')
|
||||
end
|
||||
|
||||
for _, entry in ipairs(clip) do
|
||||
local dest = utils.path_join({destination, entry.name })
|
||||
do_single_paste(entry.absolute_path, dest, action_type, action_fn)
|
||||
for _, _node in ipairs(clip) do
|
||||
local dest = utils.path_join({destination, _node.name })
|
||||
do_single_paste(_node.absolute_path, dest, action_type, action_fn)
|
||||
end
|
||||
|
||||
clipboard[action_type] = {}
|
||||
@ -159,13 +159,13 @@ end
|
||||
function M.copy_path(node)
|
||||
local absolute_path = node.absolute_path
|
||||
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)
|
||||
end
|
||||
|
||||
function M.copy_absolute_path(node)
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ local M = {}
|
||||
|
||||
local function focus_file(file)
|
||||
local _, i = utils.find_node(
|
||||
lib.Tree.entries,
|
||||
lib.Tree.nodes,
|
||||
function(node) return node.absolute_path == file end
|
||||
)
|
||||
require'nvim-tree.view'.set_cursor({i+1, 1})
|
||||
@ -33,7 +33,7 @@ local function create_file(file)
|
||||
events._dispatch_file_created(file)
|
||||
end
|
||||
|
||||
local function get_num_entries(iter)
|
||||
local function get_num_nodes(iter)
|
||||
local i = 0
|
||||
for _ in iter do
|
||||
i = i + 1
|
||||
@ -43,7 +43,7 @@ end
|
||||
|
||||
local function get_containing_folder(node)
|
||||
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)
|
||||
end
|
||||
local node_name_size = #(node.name or '')
|
||||
@ -62,7 +62,7 @@ function M.fn(node)
|
||||
if node.name == '..' then
|
||||
node = {
|
||||
absolute_path = lib.Tree.cwd,
|
||||
entries = lib.Tree.entries,
|
||||
nodes = lib.Tree.nodes,
|
||||
open = true,
|
||||
}
|
||||
end
|
||||
@ -72,12 +72,12 @@ function M.fn(node)
|
||||
if not file then return end
|
||||
|
||||
-- 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 path_to_create = ''
|
||||
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
|
||||
for path in utils.path_split(file) do
|
||||
idx = idx + 1
|
||||
@ -87,7 +87,7 @@ function M.fn(node)
|
||||
else
|
||||
path_to_create = utils.path_join({path_to_create, p})
|
||||
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)
|
||||
elseif not utils.file_exists(path_to_create) then
|
||||
local success = uv.fs_mkdir(path_to_create, 493)
|
||||
|
||||
@ -82,7 +82,7 @@ local keypress_funcs = {
|
||||
if node.name == '..' then
|
||||
return
|
||||
end
|
||||
if node.entries ~= nil then
|
||||
if node.nodes ~= nil then
|
||||
return lib.expand_or_collapse(node)
|
||||
end
|
||||
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
|
||||
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)
|
||||
elseif action == "cd" then
|
||||
return
|
||||
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)
|
||||
elseif node.entries ~= nil then
|
||||
elseif node.nodes ~= nil then
|
||||
lib.expand_or_collapse(node)
|
||||
else
|
||||
require'nvim-tree.actions.open-file'.fn(action, node.absolute_path)
|
||||
|
||||
@ -13,16 +13,16 @@ local function get_line_from_node(node, find_parent)
|
||||
end
|
||||
|
||||
local line = 2
|
||||
local function iter(entries, recursive)
|
||||
for _, entry in ipairs(entries) do
|
||||
local n = lib().get_last_group_node(entry)
|
||||
local function iter(nodes, recursive)
|
||||
for _, _node in ipairs(nodes) do
|
||||
local n = lib().get_last_group_node(_node)
|
||||
if node_path == n.absolute_path then
|
||||
return line, entry
|
||||
return line, _node
|
||||
end
|
||||
|
||||
line = line + 1
|
||||
if entry.open == true and recursive then
|
||||
local _, child = iter(entry.entries, recursive)
|
||||
if _node.open == true and recursive then
|
||||
local _, child = iter(_node.nodes, recursive)
|
||||
if child ~= nil then return line, child end
|
||||
end
|
||||
end
|
||||
@ -42,7 +42,7 @@ function M.parent_node(node, should_close)
|
||||
node.open = false
|
||||
altered_tree = true
|
||||
else
|
||||
local line, parent = iter(lib().Tree.entries, true)
|
||||
local line, parent = iter(lib().Tree.nodes, true)
|
||||
if parent == nil then
|
||||
line = 1
|
||||
elseif should_close then
|
||||
@ -69,9 +69,9 @@ function M.sibling(direction)
|
||||
local line = 0
|
||||
local parent, _
|
||||
|
||||
-- Check if current node is already at root entries
|
||||
for index, entry in ipairs(lib().Tree.entries) do
|
||||
if node_path == entry.absolute_path then
|
||||
-- Check if current node is already at root nodes
|
||||
for index, _node in ipairs(lib().Tree.nodes) do
|
||||
if node_path == _node.absolute_path then
|
||||
line = index
|
||||
end
|
||||
end
|
||||
@ -79,9 +79,9 @@ function M.sibling(direction)
|
||||
if line > 0 then
|
||||
parent = lib().Tree
|
||||
else
|
||||
_, parent = iter(lib().Tree.entries, true)
|
||||
if parent ~= nil and #parent.entries > 1 then
|
||||
line, _ = get_line_from_node(node)(parent.entries)
|
||||
_, parent = iter(lib().Tree.nodes, true)
|
||||
if parent ~= nil and #parent.nodes > 1 then
|
||||
line, _ = get_line_from_node(node)(parent.nodes)
|
||||
end
|
||||
|
||||
-- Ignore parent line count
|
||||
@ -91,12 +91,12 @@ function M.sibling(direction)
|
||||
local index = line + direction
|
||||
if index < 1 then
|
||||
index = 1
|
||||
elseif index > #parent.entries then
|
||||
index = #parent.entries
|
||||
elseif index > #parent.nodes then
|
||||
index = #parent.nodes
|
||||
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})
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,7 +58,7 @@ function M.fn(node)
|
||||
local ans = utils.get_user_input_char()
|
||||
utils.clear_prompt()
|
||||
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)
|
||||
if not success then
|
||||
return a.nvim_err_writeln('Could not remove '..node.name)
|
||||
|
||||
@ -61,7 +61,7 @@ function M.fn(node)
|
||||
|
||||
-- trashing
|
||||
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()
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
lib.refresh_tree()
|
||||
|
||||
@ -111,7 +111,7 @@ function M.update()
|
||||
buffer_severity = from_nvim_lsp()
|
||||
end
|
||||
|
||||
local nodes = require'nvim-tree.lib'.Tree.entries
|
||||
local nodes = require'nvim-tree.lib'.Tree.nodes
|
||||
if #signs then
|
||||
vim.fn.sign_unplacelist(vim.tbl_map(function(sign)
|
||||
return {
|
||||
|
||||
@ -29,7 +29,7 @@ local function dir_new(cwd, name, status, parent_ignored)
|
||||
open = false,
|
||||
group_next = nil, -- If node is grouped, this points to the next child dir/link node
|
||||
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]),
|
||||
}
|
||||
end
|
||||
@ -62,10 +62,10 @@ local function link_new(cwd, name, status, parent_ignored)
|
||||
local absolute_path = utils.path_join({ cwd, name })
|
||||
local link_to = luv.fs_realpath(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
|
||||
open = false
|
||||
entries = {}
|
||||
nodes = {}
|
||||
end
|
||||
|
||||
local last_modified = 0
|
||||
@ -80,7 +80,7 @@ local function link_new(cwd, name, status, parent_ignored)
|
||||
last_modified = last_modified,
|
||||
open = open,
|
||||
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],
|
||||
}
|
||||
end
|
||||
@ -108,9 +108,9 @@ local function node_comparator(a, b)
|
||||
if not (a and b) then
|
||||
return true
|
||||
end
|
||||
if a.entries and not b.entries then
|
||||
if a.nodes and not b.nodes then
|
||||
return true
|
||||
elseif not a.entries and b.entries then
|
||||
elseif not a.nodes and b.nodes then
|
||||
return false
|
||||
end
|
||||
|
||||
@ -123,8 +123,8 @@ end
|
||||
local function should_ignore(path)
|
||||
local basename = utils.path_basename(path)
|
||||
|
||||
for _, entry in ipairs(M.exclude_list) do
|
||||
if path:match(entry) then
|
||||
for _, node in ipairs(M.exclude_list) do
|
||||
if path:match(node) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
@ -166,28 +166,28 @@ function M.refresh(nodes, cwd, parent_node, status)
|
||||
return
|
||||
end
|
||||
|
||||
local named_entries = {}
|
||||
local cached_entries = {}
|
||||
local entries_idx = {}
|
||||
local named_nodes = {}
|
||||
local cached_nodes = {}
|
||||
local nodes_idx = {}
|
||||
for i, node in ipairs(nodes) do
|
||||
node.git_status = (parent_node and parent_node.git_status == '!!' and '!!')
|
||||
or (status.files and status.files[node.absolute_path])
|
||||
or (status.dirs and status.dirs[node.absolute_path])
|
||||
cached_entries[i] = node.name
|
||||
entries_idx[node.name] = i
|
||||
named_entries[node.name] = node
|
||||
cached_nodes[i] = node.name
|
||||
nodes_idx[node.name] = i
|
||||
named_nodes[node.name] = node
|
||||
end
|
||||
|
||||
local dirs = {}
|
||||
local links = {}
|
||||
local files = {}
|
||||
local new_entries = {}
|
||||
local num_new_entries = 0
|
||||
local new_nodes = {}
|
||||
local num_new_nodes = 0
|
||||
|
||||
while true do
|
||||
local name, t = luv.fs_scandir_next(handle)
|
||||
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})
|
||||
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
|
||||
table.insert(dirs, name)
|
||||
new_entries[name] = true
|
||||
new_nodes[name] = true
|
||||
elseif t == 'file' then
|
||||
table.insert(files, name)
|
||||
new_entries[name] = true
|
||||
new_nodes[name] = true
|
||||
elseif t == 'link' then
|
||||
table.insert(links, name)
|
||||
new_entries[name] = true
|
||||
new_nodes[name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -213,11 +213,11 @@ function M.refresh(nodes, cwd, parent_node, status)
|
||||
local next_node = parent_node.group_next
|
||||
if next_node then
|
||||
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
|
||||
-- either way: sever the group link on current dir
|
||||
parent_node.group_next = nil
|
||||
named_entries[next_node.name] = next_node
|
||||
named_nodes[next_node.name] = next_node
|
||||
else
|
||||
M.refresh(nodes, next_node.absolute_path, next_node, status)
|
||||
return
|
||||
@ -225,18 +225,18 @@ function M.refresh(nodes, cwd, parent_node, status)
|
||||
end
|
||||
|
||||
local idx = 1
|
||||
for _, name in ipairs(cached_entries) do
|
||||
local node = named_entries[name]
|
||||
for _, name in ipairs(cached_nodes) do
|
||||
local node = named_nodes[name]
|
||||
if node and node.link_to then
|
||||
-- If the link has been modified: remove it in case the link target has changed.
|
||||
local stat = luv.fs_stat(node.absolute_path)
|
||||
if stat and node.last_modified ~= stat.mtime.sec then
|
||||
new_entries[name] = nil
|
||||
named_entries[name] = nil
|
||||
new_nodes[name] = nil
|
||||
named_nodes[name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if not new_entries[name] then
|
||||
if not new_nodes[name] then
|
||||
table.remove(nodes, idx)
|
||||
else
|
||||
idx = idx + 1
|
||||
@ -244,28 +244,28 @@ function M.refresh(nodes, cwd, parent_node, status)
|
||||
end
|
||||
|
||||
local all = {
|
||||
{ entries = 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 },
|
||||
{ entries = files, fn = file_new, check = function() return true end }
|
||||
{ nodes = dirs, fn = dir_new, check = function(_, abs) return luv.fs_access(abs, 'R') end },
|
||||
{ nodes = links, fn = link_new, check = function(name) return name ~= nil end },
|
||||
{ nodes = files, fn = file_new, check = function() return true end }
|
||||
}
|
||||
|
||||
local prev = nil
|
||||
local change_prev
|
||||
local new_nodes_added = false
|
||||
for _, e in ipairs(all) do
|
||||
for _, name in ipairs(e.entries) do
|
||||
for _, name in ipairs(e.nodes) do
|
||||
change_prev = true
|
||||
if not named_entries[name] then
|
||||
if not named_nodes[name] then
|
||||
local n = e.fn(cwd, name, status)
|
||||
if e.check(n.link_to, n.absolute_path) then
|
||||
new_nodes_added = true
|
||||
idx = 1
|
||||
if prev then
|
||||
idx = entries_idx[prev] + 1
|
||||
idx = nodes_idx[prev] + 1
|
||||
end
|
||||
table.insert(nodes, idx, n)
|
||||
entries_idx[name] = idx
|
||||
cached_entries[idx] = name
|
||||
nodes_idx[name] = idx
|
||||
cached_nodes[idx] = name
|
||||
else
|
||||
change_prev = false
|
||||
end
|
||||
@ -285,7 +285,7 @@ function M.refresh(nodes, cwd, parent_node, status)
|
||||
end
|
||||
end
|
||||
|
||||
function M.explore(entries, cwd, parent_node, status)
|
||||
function M.explore(nodes, cwd, parent_node, status)
|
||||
local handle = luv.fs_scandir(cwd)
|
||||
if type(handle) == 'string' then
|
||||
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
|
||||
parent_node.group_next = child_node
|
||||
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
|
||||
end
|
||||
end
|
||||
@ -336,23 +336,23 @@ function M.explore(entries, cwd, parent_node, status)
|
||||
for _, dirname in ipairs(dirs) do
|
||||
local dir = dir_new(cwd, dirname, status, parent_node_ignored)
|
||||
if luv.fs_access(dir.absolute_path, 'R') then
|
||||
table.insert(entries, dir)
|
||||
table.insert(nodes, dir)
|
||||
end
|
||||
end
|
||||
|
||||
for _, linkname in ipairs(links) do
|
||||
local link = link_new(cwd, linkname, status, parent_node_ignored)
|
||||
if link.link_to ~= nil then
|
||||
table.insert(entries, link)
|
||||
table.insert(nodes, link)
|
||||
end
|
||||
end
|
||||
|
||||
for _, filename in ipairs(files) do
|
||||
local file = file_new(cwd, filename, status, parent_node_ignored)
|
||||
table.insert(entries, file)
|
||||
table.insert(nodes, file)
|
||||
end
|
||||
|
||||
utils.merge_sort(entries, node_comparator)
|
||||
utils.merge_sort(nodes, node_comparator)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
@ -366,8 +366,8 @@ function M.setup(opts)
|
||||
|
||||
local custom_filter = opts.filters.custom
|
||||
if custom_filter and #custom_filter > 0 then
|
||||
for _, entry in pairs(custom_filter) do
|
||||
M.ignore_list[entry] = true
|
||||
for _, filter_name in pairs(custom_filter) do
|
||||
M.ignore_list[filter_name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -14,7 +14,7 @@ local first_init_done = false
|
||||
local M = {}
|
||||
|
||||
M.Tree = {
|
||||
entries = {},
|
||||
nodes = {},
|
||||
cwd = nil,
|
||||
target_winid = nil,
|
||||
}
|
||||
@ -27,14 +27,14 @@ local function load_children(cwd, children, parent)
|
||||
end
|
||||
|
||||
function M.init(with_open, foldername)
|
||||
M.Tree.entries = {}
|
||||
M.Tree.nodes = {}
|
||||
M.Tree.cwd = foldername or luv.cwd()
|
||||
|
||||
if with_open then
|
||||
M.open()
|
||||
end
|
||||
|
||||
load_children(M.Tree.cwd, M.Tree.entries)
|
||||
load_children(M.Tree.cwd, M.Tree.nodes)
|
||||
|
||||
if not first_init_done then
|
||||
events._dispatch_ready()
|
||||
@ -48,14 +48,14 @@ end
|
||||
|
||||
local function get_node_at_line(line)
|
||||
local index = view.View.hide_root_folder and 1 or 2
|
||||
local function iter(entries)
|
||||
for _, node in ipairs(entries) do
|
||||
local function iter(nodes)
|
||||
for _, node in ipairs(nodes) do
|
||||
if index == line then
|
||||
return node
|
||||
end
|
||||
index = index + 1
|
||||
if node.open == true then
|
||||
local child = iter(node.entries)
|
||||
local child = iter(node.nodes)
|
||||
if child ~= nil then return child end
|
||||
end
|
||||
end
|
||||
@ -83,7 +83,7 @@ function M.get_node_at_cursor()
|
||||
if M.Tree.cwd == "/" then
|
||||
line = line + 1
|
||||
end
|
||||
return get_node_at_line(line)(M.Tree.entries)
|
||||
return get_node_at_line(line)(M.Tree.nodes)
|
||||
end
|
||||
end
|
||||
|
||||
@ -99,10 +99,10 @@ end
|
||||
function M.expand_or_collapse(node)
|
||||
node.open = not node.open
|
||||
if node.has_children then node.has_children = false end
|
||||
if #node.entries == 0 then
|
||||
if #node.nodes == 0 then
|
||||
load_children(
|
||||
node.link_to or node.absolute_path,
|
||||
node.entries,
|
||||
node.nodes,
|
||||
node
|
||||
)
|
||||
else
|
||||
@ -114,10 +114,10 @@ end
|
||||
|
||||
local function refresh_nodes(node, projects)
|
||||
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 {})
|
||||
for _, entry in ipairs(node.entries) do
|
||||
if entry.entries and entry.open then
|
||||
refresh_nodes(entry, projects)
|
||||
explorer.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
|
||||
@ -145,13 +145,13 @@ end
|
||||
local function 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.entries) do
|
||||
if node.entries then
|
||||
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.entries and #node.entries > 0 then
|
||||
if node.nodes and #node.nodes > 0 then
|
||||
reload_node_status(node, projects)
|
||||
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)
|
||||
if path_matches then
|
||||
if #node.entries == 0 then
|
||||
if #node.nodes == 0 then
|
||||
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)
|
||||
if status.dirs or status.files then
|
||||
reload_node_status(node, git.projects)
|
||||
@ -204,16 +204,16 @@ function M.set_index_and_redraw(fname)
|
||||
node.open = true
|
||||
tree_altered = true
|
||||
end
|
||||
if iterate_nodes(node.entries) ~= nil then
|
||||
if iterate_nodes(node.nodes) ~= nil then
|
||||
return i
|
||||
end
|
||||
elseif node.open == true then
|
||||
iterate_nodes(node.entries)
|
||||
iterate_nodes(node.nodes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local index = iterate_nodes(M.Tree.entries)
|
||||
local index = iterate_nodes(M.Tree.nodes)
|
||||
if tree_altered then
|
||||
M.redraw()
|
||||
end
|
||||
|
||||
@ -284,7 +284,7 @@ local function update_draw_data(tree, depth, markers)
|
||||
index = 1
|
||||
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 offset = string.len(padding)
|
||||
if depth > 0 then
|
||||
@ -293,8 +293,8 @@ local function update_draw_data(tree, depth, markers)
|
||||
|
||||
local git_hl = get_git_hl(node)
|
||||
|
||||
if node.entries then
|
||||
local has_children = #node.entries ~= 0 or node.has_children
|
||||
if node.nodes then
|
||||
local has_children = #node.nodes ~= 0 or node.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 ""
|
||||
-- INFO: this is mandatory in order to keep gui attributes (bold/italics)
|
||||
|
||||
@ -6,7 +6,7 @@ end
|
||||
|
||||
local function get_padding_arrows(icon_state)
|
||||
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']
|
||||
return string.rep(' ', depth - 2)..icon..' '
|
||||
end
|
||||
@ -18,9 +18,9 @@ local function get_padding_indent_markers(depth, idx, tree, _, markers)
|
||||
local padding = ""
|
||||
if depth ~= 0 then
|
||||
local rdepth = depth/2
|
||||
markers[rdepth] = idx ~= #tree.entries
|
||||
markers[rdepth] = idx ~= #tree.nodes
|
||||
for i=1,rdepth do
|
||||
if idx == #tree.entries and i == rdepth then
|
||||
if idx == #tree.nodes and i == rdepth then
|
||||
padding = padding..'└ '
|
||||
elseif markers[i] then
|
||||
padding = padding..'│ '
|
||||
|
||||
@ -90,8 +90,8 @@ function M.find_node(_nodes, _fn)
|
||||
local i = 1
|
||||
for _, node in ipairs(nodes) do
|
||||
if fn(node) then return node, i end
|
||||
if node.open and #node.entries > 0 then
|
||||
local n, idx = iter(node.entries, fn)
|
||||
if node.open and #node.nodes > 0 then
|
||||
local n, idx = iter(node.nodes, fn)
|
||||
i = i + idx
|
||||
if n then return n, i end
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user