Skip to content

Commit

Permalink
feat: configurable indent level
Browse files Browse the repository at this point in the history
  • Loading branch information
sand4rt committed Sep 28, 2024
1 parent a77af2e commit 95faa5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ use {
},
indent = {
indent_size = 2,
level = 2,
padding = 1, -- extra padding on left hand side
-- indent guides
with_markers = true,
Expand Down
1 change: 1 addition & 0 deletions doc/neo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ for each source, or just do it once in the default_component_configs section:
indent_marker = "│",
last_indent_marker = "└",
indent_size = 2,
level = 2
},
},
})
Expand Down
35 changes: 16 additions & 19 deletions lua/neo-tree/sources/common/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ M.indent = function(config, node, state)
local skip_marker = state.skip_marker_at_level
local indent_size = config.indent_size or 2
local padding = config.padding or 0
local start_level = config.level or 2
local level = node.level
local with_markers = config.with_markers
local with_expanders = config.with_expanders == nil and file_nesting.is_enabled()
Expand All @@ -403,7 +404,7 @@ M.indent = function(config, node, state)
end
end

if indent_size == 0 or level < 2 or not with_markers then
if indent_size == 0 or level < 0 or not with_markers then
local len = indent_size * level + padding
local expander = get_expander()
if level == 0 or not expander then
Expand All @@ -426,24 +427,20 @@ M.indent = function(config, node, state)
table.insert(indent, { text = string.rep(" ", padding) })
end

for i = 1, level do
local char = ""
local spaces_count = indent_size
local highlight = nil

if i > 1 and not skip_marker[i] or i == level then
spaces_count = spaces_count - 1
char = indent_marker
highlight = marker_highlight
if i == level then
local expander = get_expander()
if expander then
char = expander
highlight = expander_highlight
elseif node.is_last_child then
char = last_indent_marker
spaces_count = spaces_count - (vim.api.nvim_strwidth(last_indent_marker) - 1)
end
for i = start_level, level do
local char = indent_marker
local spaces_count = indent_size - 1
local highlight = marker_highlight

-- Handle the last indent marker and expanders
if i == level then
local expander = get_expander()
if expander then
char = expander
highlight = expander_highlight
elseif node.is_last_child then
char = last_indent_marker
spaces_count = spaces_count - (strlen(last_indent_marker) - 1)
end
end

Expand Down

0 comments on commit 95faa5d

Please sign in to comment.