Skip to content

fix(#1406): allow nvim-tree.renderer.icons.show.folder_arrow #1408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ UI rendering setup
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.show.folder_arrow*
Show a small arrow before the folder icon.
Requires |renderer.icons.show.folder| `= true` and |renderer.indent_markers.enable| `= false`
Show a small arrow before the folder node. Arrow will be a part of the
node when using |renderer.indent_markers|.
Type: `boolean`, Default: `true`

*nvim-tree.renderer.icons.show.git*
Expand Down
9 changes: 2 additions & 7 deletions lua/nvim-tree/renderer/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Builder.__index = Builder
function Builder.new(root_cwd)
return setmetatable({
index = 0,
depth = nil,
depth = 0,
highlights = {},
lines = {},
markers = {},
Expand All @@ -19,11 +19,6 @@ function Builder.new(root_cwd)
}, Builder)
end

function Builder:configure_initial_depth(show_arrows)
self.depth = show_arrows and 2 or 0
return self
end

function Builder:configure_root_modifier(root_folder_modifier)
self.root_folder_modifier = root_folder_modifier or ":~"
return self
Expand Down Expand Up @@ -232,7 +227,7 @@ end
function Builder:_build_line(node, idx, num_children)
local padding = pad.get_padding(self.depth, idx, num_children, node, self.markers)

if self.depth > 0 then
if string.len(padding) > 0 then
self:_insert_highlight("NvimTreeIndentMarker", 0, string.len(padding))
end

Expand Down
41 changes: 22 additions & 19 deletions lua/nvim-tree/renderer/components/padding.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
local M = {}

function M.get_padding(depth)
return string.rep(" ", depth)
end

local function get_padding_arrows()
return function(depth, _, _, node)
if node.nodes then
local icon = M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"]
return string.rep(" ", depth - 2) .. icon .. " "
end
return string.rep(" ", depth)
end
end

local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
local function get_padding_indent_markers(depth, idx, nodes_number, markers)
local padding = ""

if depth ~= 0 then
local rdepth = depth / 2
markers[rdepth] = idx ~= nodes_number
Expand All @@ -34,14 +21,30 @@ local function get_padding_indent_markers(depth, idx, nodes_number, _, markers)
return padding
end

function M.reload_padding_function()
if M.config.icons.show.folder and M.config.icons.show.folder_arrow then
M.get_padding = get_padding_arrows()
local function get_padding_arrows(node, indent)
if node.nodes then
return M.config.icons.glyphs.folder[node.open and "arrow_open" or "arrow_closed"] .. " "
elseif indent then
return " "
else
return ""
end
end

function M.get_padding(depth, idx, nodes_number, node, markers)
local padding = ""

if M.config.indent_markers.enable then
M.get_padding = get_padding_indent_markers
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers)
else
padding = padding .. string.rep(" ", depth)
end

if M.config.icons.show.folder_arrow then
padding = padding .. get_padding_arrows(node, not M.config.indent_markers.enable)
end

return padding
end

function M.setup(opts)
Expand Down
6 changes: 0 additions & 6 deletions lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ function M.render_hl(bufnr, hl)
end
end

local function should_show_arrows()
return not M.config.indent_markers.enable and M.config.icons.show.folder and M.config.icons.show.folder_arrow
end

local picture_map = {
jpg = true,
jpeg = true,
Expand All @@ -60,7 +56,6 @@ function M.draw()
local ps = log.profile_start "draw"

local cursor = api.nvim_win_get_cursor(view.get_winnr())
_padding.reload_padding_function()
icon_component.reset_config()

local lines, hl
Expand All @@ -69,7 +64,6 @@ function M.draw()
lines, hl = help.compute_lines()
else
lines, hl, signs = Builder.new(core.get_cwd())
:configure_initial_depth(should_show_arrows())
:configure_root_modifier(M.config.root_folder_modifier)
:configure_trailing_slash(M.config.add_trailing)
:configure_special_files(M.config.special_files)
Expand Down
10 changes: 7 additions & 3 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ local M = {}

local events = require "nvim-tree.events"

local function get_win_sep_hl()
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
local has_win_sep = pcall(vim.cmd, "silent hi WinSeparator")
return has_win_sep and "WinSeparator:NvimTreeWinSeparator" or "VertSplit:NvimTreeWinSeparator"
end

M.View = {
adaptive_size = false,
centralize_selection = false,
Expand All @@ -29,9 +35,7 @@ M.View = {
"EndOfBuffer:NvimTreeEndOfBuffer",
"Normal:NvimTreeNormal",
"CursorLine:NvimTreeCursorLine",
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
pcall(vim.cmd, "silent hi WinSeparator") and "WinSeparator:NvimTreeWinSeparator"
or "VertSplit:NvimTreeWinSeparator",
get_win_sep_hl(),
"StatusLine:NvimTreeStatusLine",
"StatusLineNC:NvimTreeStatuslineNC",
"SignColumn:NvimTreeSignColumn",
Expand Down