This commit is contained in:
Alexander Courtis 2024-11-08 18:18:51 +11:00
parent f2dd8a4397
commit ddd28ecd01
15 changed files with 114 additions and 113 deletions

View File

@ -30,11 +30,11 @@ function Filters:new(args)
self.enabled = self.explorer.opts.filters.enable
self.states = {
custom = true,
dotfiles = self.explorer.opts.filters.dotfiles,
custom = true,
dotfiles = self.explorer.opts.filters.dotfiles,
git_ignored = self.explorer.opts.filters.git_ignored,
git_clean = self.explorer.opts.filters.git_clean,
no_buffer = self.explorer.opts.filters.no_buffer,
git_clean = self.explorer.opts.filters.git_clean,
no_buffer = self.explorer.opts.filters.no_buffer,
no_bookmark = self.explorer.opts.filters.no_bookmark,
}

View File

@ -200,10 +200,10 @@ function Explorer:reload(node, project)
-- To reset we must 'zero' everything that we use
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
bookmark = 0,
})
@ -234,11 +234,11 @@ function Explorer:reload(node, project)
if not nodes_by_path[abs] then
local new_child = node_factory.create({
explorer = self,
parent = node,
explorer = self,
parent = node,
absolute_path = abs,
name = name,
fs_stat = stat
name = name,
fs_stat = stat
})
if new_child then
table.insert(node.nodes, new_child)
@ -355,10 +355,10 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
local filter_status = parent.filters:prepare(project)
node.hidden_stats = vim.tbl_deep_extend("force", node.hidden_stats or {}, {
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
bookmark = 0,
})
@ -378,11 +378,11 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
local child = node_factory.create({
explorer = self,
parent = node,
explorer = self,
parent = node,
absolute_path = abs,
name = name,
fs_stat = stat
name = name,
fs_stat = stat
})
if child then
table.insert(node.nodes, child)

View File

@ -169,21 +169,21 @@ local function create_overlay(self)
if view.View.float.enable then
-- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds({
event = "WinLeave",
event = "WinLeave",
pattern = "NvimTree_*",
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
group = vim.api.nvim_create_augroup("NvimTree", { clear = false }),
})
end
configure_buffer_overlay(self)
overlay_winnr = vim.api.nvim_open_win(overlay_bufnr, true, {
col = 1,
row = 0,
col = 1,
row = 0,
relative = "cursor",
width = calculate_overlay_win_width(self),
height = 1,
border = "none",
style = "minimal",
width = calculate_overlay_win_width(self),
height = 1,
border = "none",
style = "minimal",
})
if vim.fn.has("nvim-0.10") == 1 then

View File

@ -138,12 +138,12 @@ function Sorter:sort(t)
for _, n in ipairs(t) do
table.insert(t_user, {
absolute_path = n.absolute_path,
executable = n.executable,
extension = n.extension,
filetype = vim.filetype.match({ filename = n.name }),
link_to = n.link_to,
name = n.name,
type = n.type,
executable = n.executable,
extension = n.extension,
filetype = vim.filetype.match({ filename = n.name }),
link_to = n.link_to,
name = n.name,
type = n.type,
})
table.insert(origin_index, n)
end

View File

@ -130,11 +130,11 @@ function M.reload_project(toplevel, path, callback)
---@type GitRunnerArgs
local args = {
toplevel = toplevel,
path = path,
toplevel = toplevel,
path = path,
list_untracked = git_utils.should_show_untracked(toplevel),
list_ignored = true,
timeout = M.config.git.timeout,
list_ignored = true,
timeout = M.config.git.timeout,
}
if callback then
@ -276,10 +276,10 @@ function M.load_project(path)
end
local path_xys = GitRunner:run({
toplevel = toplevel,
toplevel = toplevel,
list_untracked = git_utils.should_show_untracked(toplevel),
list_ignored = true,
timeout = M.config.git.timeout,
list_ignored = true,
timeout = M.config.git.timeout,
})
local watcher = nil
@ -299,10 +299,10 @@ function M.load_project(path)
local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" })
watcher = Watcher:create({
path = git_dir,
files = WATCHED_FILES,
path = git_dir,
files = WATCHED_FILES,
callback = callback,
data = {
data = {
toplevel = toplevel,
}
})
@ -310,8 +310,8 @@ function M.load_project(path)
if path_xys then
M._projects_by_toplevel[toplevel] = {
files = path_xys,
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
files = path_xys,
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
watcher = watcher,
}
return M._projects_by_toplevel[toplevel]

View File

@ -94,8 +94,8 @@ function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
local untracked = self.args.list_untracked and "-u" or nil
local ignored = (self.args.list_untracked and self.args.list_ignored) and "--ignored=matching" or "--ignored=no"
return {
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.args.path },
cwd = self.args.toplevel,
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.args.path },
cwd = self.args.toplevel,
stdio = { nil, stdout_handle, stderr_handle },
}
end

View File

@ -172,8 +172,8 @@ function M.git_status_dir(parent_ignored, project, path, path_fallback)
elseif project then
ns = {
file = project.files and (project.files[path] or project.files[path_fallback]),
dir = project.dirs and {
direct = project.dirs.direct and project.dirs.direct[path],
dir = project.dirs and {
direct = project.dirs.direct and project.dirs.direct[path],
indirect = project.dirs.indirect and project.dirs.indirect[path],
},
}

View File

@ -48,10 +48,10 @@ function DirectoryLinkNode:highlighted_icon()
if self.open then
str = self.explorer.opts.renderer.icons.glyphs.folder.symlink_open
hl = "NvimTreeOpenedFolderIcon"
hl = "NvimTreeOpenedFolderIcon"
else
str = self.explorer.opts.renderer.icons.glyphs.folder.symlink
hl = "NvimTreeClosedFolderIcon"
hl = "NvimTreeClosedFolderIcon"
end
return { str = str, hl = { hl } }
@ -64,8 +64,9 @@ function DirectoryLinkNode:highlighted_name()
if self.explorer.opts.renderer.symlink_destination then
local link_to = utils.path_relative(self.link_to, self.explorer.absolute_path)
name.str = string.format("%s%s%s", name.str, self.explorer.opts.renderer.icons.symlink_arrow, link_to)
name.hl = { "NvimTreeSymlinkFolderName" }
name.str = string.format("%s%s%s", name.str, self.explorer.opts.renderer.icons.symlink_arrow, link_to)
name.hl = { "NvimTreeSymlinkFolderName" }
end
return name

View File

@ -273,12 +273,12 @@ end
---Create a sanitized partial copy of a node, populating children recursively.
---@return DirectoryNode cloned
function DirectoryNode:clone()
local clone = Node.clone(self) --[[@as DirectoryNode]]
local clone = Node.clone(self) --[[@as DirectoryNode]]
clone.has_children = self.has_children
clone.group_next = nil
clone.nodes = {}
clone.open = self.open
clone.group_next = nil
clone.nodes = {}
clone.open = self.open
clone.hidden_stats = nil
for _, child in ipairs(self.nodes) do

View File

@ -125,17 +125,17 @@ function Node:clone()
---@type Node
local clone = {
type = self.type,
explorer = explorer_placeholder,
type = self.type,
explorer = explorer_placeholder,
absolute_path = self.absolute_path,
executable = self.executable,
fs_stat = self.fs_stat,
git_status = self.git_status,
hidden = self.hidden,
name = self.name,
parent = nil,
diag_status = nil,
is_dot = self.is_dot,
executable = self.executable,
fs_stat = self.fs_stat,
git_status = self.git_status,
hidden = self.hidden,
name = self.name,
parent = nil,
diag_status = nil,
is_dot = self.is_dot,
}
return clone

View File

@ -408,11 +408,11 @@ function Builder:setup_hidden_display_function(opts)
-- In case of missing field such as live_filter we zero it, otherwise keep field as is
hidden_stats = vim.tbl_deep_extend("force", {
live_filter = 0,
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
bookmark = 0,
git = 0,
buf = 0,
dotfile = 0,
custom = 0,
bookmark = 0,
}, hidden_stats or {})
local ok, result = pcall(hidden_display, hidden_stats)

View File

@ -57,13 +57,13 @@ local function show()
end
M.popup_win = vim.api.nvim_open_win(vim.api.nvim_create_buf(false, false), false, {
relative = "win",
row = 0,
bufpos = { vim.api.nvim_win_get_cursor(0)[1] - 1, 0 },
width = math.min(text_width, vim.o.columns - 2),
height = 1,
relative = "win",
row = 0,
bufpos = { vim.api.nvim_win_get_cursor(0)[1] - 1, 0 },
width = math.min(text_width, vim.o.columns - 2),
height = 1,
noautocmd = true,
style = "minimal",
style = "minimal",
})
local ns_id = vim.api.nvim_get_namespaces()["NvimTreeHighlights"]

View File

@ -52,14 +52,14 @@ end
---@param glyphs GitGlyphsByStatus
function DecoratorGit:build_icons_by_status(glyphs)
self.icons_by_status = {}
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
self.icons_by_status = {}
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
self.icons_by_status.renamed = { str = glyphs.renamed, hl = { "NvimTreeGitRenamedIcon" }, ord = 3 }
self.icons_by_status.deleted = { str = glyphs.deleted, hl = { "NvimTreeGitDeletedIcon" }, ord = 4 }
self.icons_by_status.unmerged = { str = glyphs.unmerged, hl = { "NvimTreeGitMergeIcon" }, ord = 5 }
self.icons_by_status.untracked = { str = glyphs.untracked, hl = { "NvimTreeGitNewIcon" }, ord = 6 }
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
self.icons_by_status.ignored = { str = glyphs.ignored, hl = { "NvimTreeGitIgnoredIcon" }, ord = 7 }
end
---@param icons GitIconsByXY
@ -96,7 +96,7 @@ function DecoratorGit:build_icons_by_xy(icons)
["DD"] = { icons.deleted },
["DU"] = { icons.deleted, icons.unmerged },
["!!"] = { icons.ignored },
dirty = { icons.unstaged },
dirty = { icons.unstaged },
}
end
@ -115,7 +115,7 @@ function DecoratorGit:build_file_folder_hl_by_xy()
[" T"] = "NvimTreeGitFileDirtyHL",
["MM"] = "NvimTreeGitFileDirtyHL",
["AM"] = "NvimTreeGitFileDirtyHL",
dirty = "NvimTreeGitFileDirtyHL",
dirty = "NvimTreeGitFileDirtyHL",
["A "] = "NvimTreeGitFileStagedHL",
["??"] = "NvimTreeGitFileNewHL",
["AU"] = "NvimTreeGitFileMergeHL",

View File

@ -59,9 +59,9 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
for i, extname in pairs(extmarks) do
for _, mark in ipairs(extname) do
vim.api.nvim_buf_set_extmark(bufnr, namespace_extmarks_id, i, -1, {
virt_text = { { mark.str, mark.hl } },
virt_text = { { mark.str, mark.hl } },
virt_text_pos = "right_align",
hl_mode = "combine",
hl_mode = "combine",
})
end
end
@ -69,8 +69,8 @@ function Renderer:_draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
vim.api.nvim_buf_clear_namespace(bufnr, namespace_virtual_lines_id, 0, -1)
for line_nr, vlines in pairs(virtual_lines) do
vim.api.nvim_buf_set_extmark(bufnr, namespace_virtual_lines_id, line_nr, 0, {
virt_lines = vlines,
virt_lines_above = false,
virt_lines = vlines,
virt_lines_above = false,
virt_lines_leftcol = true,
})
end

View File

@ -15,31 +15,31 @@ local DEFAULT_MAX_WIDTH = -1
local DEFAULT_PADDING = 1
M.View = {
adaptive_size = false,
adaptive_size = false,
centralize_selection = false,
tabpages = {},
cursors = {},
hide_root_folder = false,
live_filter = {
tabpages = {},
cursors = {},
hide_root_folder = false,
live_filter = {
prev_focused_node = nil,
},
winopts = {
winopts = {
relativenumber = false,
number = false,
list = false,
foldenable = false,
winfixwidth = true,
winfixheight = true,
spell = false,
signcolumn = "yes",
foldmethod = "manual",
foldcolumn = "0",
cursorcolumn = false,
cursorline = true,
cursorlineopt = "both",
colorcolumn = "0",
wrap = false,
winhl = table.concat({
number = false,
list = false,
foldenable = false,
winfixwidth = true,
winfixheight = true,
spell = false,
signcolumn = "yes",
foldmethod = "manual",
foldcolumn = "0",
cursorcolumn = false,
cursorline = true,
cursorlineopt = "both",
colorcolumn = "0",
wrap = false,
winhl = table.concat({
"EndOfBuffer:NvimTreeEndOfBuffer",
"CursorLine:NvimTreeCursorLine",
"CursorLineNr:NvimTreeCursorLineNr",