Skip to content

Commit 7cafb25

Browse files
committed
fix(indent): refactor conditionals
1 parent 5e1ff45 commit 7cafb25

File tree

1 file changed

+38
-52
lines changed

1 file changed

+38
-52
lines changed

lua/neo-tree/sources/common/components.lua

+38-52
Original file line numberDiff line numberDiff line change
@@ -404,21 +404,20 @@ M.indent = function(config, node, state)
404404
end
405405
end
406406

407-
if indent_size == 0 or not with_markers then
408-
local len = indent_size + padding
407+
if indent_size == 0 then
409408
local expander = get_expander()
410-
if level == 0 or not expander then
411-
if marker_start_level == 0 then
412-
len = len + indent_size
413-
end
409+
local len = 0
410+
if expander then
411+
len = indent_size * level - strlen(expander) - 1
412+
return {
413+
text = string.rep(" ", len) .. expander .. " ",
414+
highlight = expander_highlight,
415+
}
416+
else
414417
return {
415418
text = string.rep(" ", len),
416419
}
417420
end
418-
return {
419-
text = string.rep(" ", len - strlen(expander) - 1) .. expander .. " ",
420-
highlight = expander_highlight,
421-
}
422421
end
423422

424423
local indent_marker = config.indent_marker or ""
@@ -430,60 +429,47 @@ M.indent = function(config, node, state)
430429
table.insert(indent, { text = string.rep(" ", padding) })
431430
end
432431

432+
local root_indent_applied = false
433+
433434
for i = 0, level do
435+
local char = ""
434436
local highlight = nil
435-
local char = marker_start_level ~= 0 and "" or " "
436-
local separator = i < marker_start_level and "" or " "
437-
local additional_spaces = string.rep(" ", math.max(0, indent_size - 2))
437+
local current_indent_size = indent_size
438+
local expander = get_expander()
438439

439-
if marker_start_level ~= 0 then
440-
if i <= 0 then
441-
additional_spaces = ""
442-
end
443-
if level == 0 then
444-
char = ""
445-
separator = ""
446-
additional_spaces = ""
440+
if i < marker_start_level then
441+
if i == 0 and not root_indent_applied then
442+
current_indent_size = 0
443+
root_indent_applied = true
444+
else
445+
current_indent_size = 0
447446
end
448447
end
449448

450-
if indent_size == 1 then
451-
separator = ""
452-
additional_spaces = ""
453-
end
454-
455-
if marker_start_level >= 2 and i > 0 then
456-
char = " "
457-
separator = " "
458-
end
459-
460-
if i >= marker_start_level then
461-
highlight = marker_highlight
462-
if i == level then
463-
if node.is_last_child then
449+
if i == level and expander and level ~= 0 then
450+
char = expander
451+
highlight = expander_highlight
452+
elseif with_markers then
453+
if i >= marker_start_level then
454+
char = indent_marker
455+
if skip_marker[i] then
456+
char = " "
457+
end
458+
if i == level and node.is_last_child then
464459
char = last_indent_marker
465-
-- proof of concept for extended markers
466-
-- if indent_size > 2 then
467-
-- separator = "─"
468-
-- end
469-
else
470-
char = indent_marker
471460
end
472-
elseif not skip_marker[i] then
473-
char = indent_marker
474-
end
475-
end
476-
477-
if i == level and i >= 1 then
478-
local expander = get_expander()
479-
if expander then
480-
char = expander
481-
highlight = expander_highlight
461+
highlight = marker_highlight
462+
elseif i < marker_start_level and i == 0 and level > 0 and not root_indent_applied then
463+
char = " "
464+
root_indent_applied = true
482465
end
466+
elseif not with_markers and not expander then
467+
char = ""
483468
end
484469

470+
local prefix = string.rep(" ", current_indent_size - strlen(char))
485471
table.insert(indent, {
486-
text = char .. separator .. additional_spaces,
472+
text = char .. prefix,
487473
highlight = highlight,
488474
no_next_padding = true,
489475
})

0 commit comments

Comments
 (0)