fix(renderer): indent markers with arrows

breaking: glyphs for indent markers should only be one block large
This commit is contained in:
kiyan
2022-07-15 09:32:14 +02:00
parent 19425c5896
commit 9a02dedd92
3 changed files with 38 additions and 15 deletions

View File

@@ -201,9 +201,9 @@ Subsequent calls to setup will replace the previous configuration.
indent_markers = {
enable = false,
icons = {
corner = "└ ",
edge = "│ ",
item = "│ ",
corner = "└",
edge = "│",
item = "│",
none = " ",
},
},
@@ -644,7 +644,7 @@ UI rendering setup
*nvim-tree.renderer.indent_markers.icons*
Icons shown before the file/directory.
Type: `table`, Default: `{ corner = "└ ", edge = "│ ", item = "│ ", none = " ", }`
Type: `table`, Default: `{ corner = "└", edge = "│", item = "│", none = " ", }`
*nvim-tree.renderer.icons*
Configuration options for icons.

View File

@@ -449,9 +449,9 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
indent_markers = {
enable = false,
icons = {
corner = " ",
edge = " ",
item = " ",
corner = "",
edge = "",
item = "",
none = " ",
},
},

View File

@@ -1,21 +1,44 @@
local M = {}
local function check_siblings_for_folder(node, with_arrows)
if with_arrows then
for _, n in pairs(node.parent.nodes) do
if n.nodes then
return true
end
end
end
return false
end
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, node)
local default_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
local padding = depth == 0 and default_padding or ""
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
local padding = base_padding
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 glyph
if idx == nodes_number and i == rdepth then
padding = padding .. default_padding .. M.config.indent_markers.icons.corner
glyph = M.config.indent_markers.icons.corner
elseif markers[i] and i == rdepth then
padding = padding .. default_padding .. M.config.indent_markers.icons.item
glyph = M.config.indent_markers.icons.item
elseif markers[i] then
padding = padding .. default_padding .. M.config.indent_markers.icons.edge
glyph = M.config.indent_markers.icons.edge
else
padding = padding .. default_padding .. M.config.indent_markers.icons.none
glyph = M.config.indent_markers.icons.none
end
if not with_arrows or i == 1 then
padding = padding .. glyph .. " "
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
else
padding = padding .. base_padding .. glyph .. " "
end
end
end