Skip to content

feat: add option for folder arrows to be inline with indent markers #1468

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 2 commits into from
Jul 28, 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
6 changes: 6 additions & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Subsequent calls to setup will replace the previous configuration.
root_folder_modifier = ":~",
indent_markers = {
enable = false,
inline_arrows = true,
icons = {
corner = "└",
edge = "│",
Expand Down Expand Up @@ -670,6 +671,11 @@ UI rendering setup
Display indent markers when folders are open
Type: `boolean`, Default: `false`

*nvim-tree.renderer.indent_markers.inline_arrows*
Display folder arrows in the same column as indent marker
when using |renderer.icons.show.folder_arrow|
Type: `boolean`, Default: `true`

*nvim-tree.renderer.indent_markers.icons*
Icons shown before the file/directory.
Type: `table`, Default: `{ corner = "└", edge = "│", item = "│", none = " ", }`
Expand Down
1 change: 1 addition & 0 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
root_folder_modifier = ":~",
indent_markers = {
enable = false,
inline_arrows = true,
icons = {
corner = "└",
edge = "│",
Expand Down
11 changes: 7 additions & 4 deletions lua/nvim-tree/renderer/components/padding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ local function check_siblings_for_folder(node, with_arrows)
return false
end

local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, node)
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, inline_arrows, node)
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
local padding = base_padding
local padding = (inline_arrows or depth == 0) and base_padding or ""

if depth > 0 then
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
Expand All @@ -39,8 +39,10 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit
glyph = M.config.indent_markers.icons.none
end

if not with_arrows or i == 1 then
if not with_arrows or (inline_arrows and (rdepth ~= 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
Expand Down Expand Up @@ -68,9 +70,10 @@ 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

if show_markers then
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, node)
padding = padding .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node)
else
padding = padding .. string.rep(" ", depth)
end
Expand Down