Merge branch 'master' into chore/action_cb_help_poc

This commit is contained in:
Alexander Courtis
2022-09-04 13:09:50 +10:00
23 changed files with 517 additions and 148 deletions

View File

@@ -1,4 +1,5 @@
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local git = require "nvim-tree.renderer.components.git"
local pad = require "nvim-tree.renderer.components.padding"
@@ -114,7 +115,8 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
local foldername = name .. self.trailing_slash
if node.link_to and self.symlink_destination then
local arrow = icons.i.symlink_arrow
foldername = foldername .. arrow .. node.link_to
local link_to = utils.path_relative(node.link_to, core.get_cwd())
foldername = foldername .. arrow .. link_to
end
local git_icons = self:_unwrap_git_data(git_icons_tbl, offset + #icon + (self.is_git_after and #foldername + 1 or 0))
@@ -160,7 +162,8 @@ function Builder:_build_symlink(node, padding, git_highlight, git_icons_tbl)
local arrow = icons.i.symlink_arrow
local symlink_formatted = node.name
if self.symlink_destination then
symlink_formatted = symlink_formatted .. arrow .. node.link_to
local link_to = utils.path_relative(node.link_to, core.get_cwd())
symlink_formatted = symlink_formatted .. arrow .. link_to
end
local link_highlight = git_highlight or "NvimTreeSymlink"
@@ -258,9 +261,9 @@ function Builder:_build_line(node, idx, num_children)
self.index = self.index + 1
if node.open then
self.depth = self.depth + 2
self.depth = self.depth + 1
self:build(node)
self.depth = self.depth - 2
self.depth = self.depth - 1
end
end

View File

@@ -99,6 +99,7 @@ local git_hl = {
["AD"] = "NvimTreeFileStaged",
["MD"] = "NvimTreeFileStaged",
["T "] = "NvimTreeFileStaged",
["TT"] = "NvimTreeFileStaged",
[" M"] = "NvimTreeFileDirty",
["CM"] = "NvimTreeFileDirty",
[" C"] = "NvimTreeFileDirty",

View File

@@ -25,30 +25,33 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
if depth > 0 then
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
local rdepth = depth / 2
markers[rdepth] = idx ~= nodes_number
for i = 1, rdepth do
local indent = string.rep(" ", M.config.indent_width - 1)
markers[depth] = idx ~= nodes_number
for i = 1, depth do
local glyph
if idx == nodes_number and i == rdepth then
if idx == nodes_number and i == depth then
local bottom_width = M.config.indent_width
- 2
+ (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0)
glyph = M.config.indent_markers.icons.corner
elseif markers[i] and i == rdepth then
glyph = M.config.indent_markers.icons.item
.. string.rep(M.config.indent_markers.icons.bottom, bottom_width)
.. (M.config.indent_width > 1 and " " or "")
elseif markers[i] and i == depth then
glyph = M.config.indent_markers.icons.item .. indent
elseif markers[i] then
glyph = M.config.indent_markers.icons.edge
glyph = M.config.indent_markers.icons.edge .. indent
else
glyph = M.config.indent_markers.icons.none
glyph = M.config.indent_markers.icons.none .. indent
end
if not with_arrows or (inline_arrows and (rdepth ~= i or not node.nodes)) then
padding = padding .. glyph .. " "
if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then
padding = padding .. glyph
elseif inline_arrows then
padding = padding
elseif idx == nodes_number and i == rdepth and has_folder_sibling then
padding = padding .. base_padding .. glyph .. "── "
elseif rdepth == i and not node.nodes and has_folder_sibling then
padding = padding .. base_padding .. glyph .. " " .. base_padding
elseif idx ~= nodes_number and depth == i and not node.nodes and has_folder_sibling then
padding = padding .. base_padding .. glyph .. base_padding
else
padding = padding .. base_padding .. glyph .. " "
padding = padding .. base_padding .. glyph
end
end
end
@@ -71,11 +74,12 @@ function M.get_padding(depth, idx, nodes_number, node, markers)
local show_arrows = M.config.icons.show.folder_arrow
local show_markers = M.config.indent_markers.enable
local inline_arrows = M.config.indent_markers.inline_arrows
local indent_width = M.config.indent_width
if show_markers then
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node)
else
padding = padding .. string.rep(" ", depth)
padding = padding .. string.rep(" ", depth * indent_width)
end
if show_arrows then
@@ -87,6 +91,22 @@ end
function M.setup(opts)
M.config = opts.renderer
if M.config.indent_width < 1 then
M.config.indent_width = 1
end
local function check_marker(symbol)
if #symbol == 0 then
return " "
end
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
return symbol:match "[%z\1-\127\194-\244][\128-\191]*"
end
for k, v in pairs(M.config.indent_markers.icons) do
M.config.indent_markers.icons[k] = check_marker(v)
end
end
return M