Skip to content

Commit 5e1ff45

Browse files
committed
feat(dir_indent):first draft
1 parent 79ba9e5 commit 5e1ff45

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

lua/neo-tree/defaults.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ local config = {
188188
with_markers = true,
189189
indent_marker = "",
190190
last_indent_marker = "",
191+
marker_start_level = 2, -- the directory node in which the marker should start rendering
191192
highlight = "NeoTreeIndentMarker",
192193
-- expander config, needed for nesting files
193194
with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders

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

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ M.indent = function(config, node, state)
387387

388388
local strlen = vim.fn.strdisplaywidth
389389
local skip_marker = state.skip_marker_at_level
390-
local indent_size = config.indent_size or 2
391-
local padding = config.padding or 0
392-
local start_level = config.level or 2
390+
local indent_size = config.indent_size
391+
local padding = config.padding
392+
local marker_start_level = config.marker_start_level
393393
local level = node.level
394394
local with_markers = config.with_markers
395395
local with_expanders = config.with_expanders == nil and file_nesting.is_enabled()
@@ -404,10 +404,13 @@ M.indent = function(config, node, state)
404404
end
405405
end
406406

407-
if indent_size == 0 or level < start_level or not with_markers then
408-
local len = indent_size * level + padding
407+
if indent_size == 0 or not with_markers then
408+
local len = indent_size + padding
409409
local expander = get_expander()
410410
if level == 0 or not expander then
411+
if marker_start_level == 0 then
412+
len = len + indent_size
413+
end
411414
return {
412415
text = string.rep(" ", len),
413416
}
@@ -420,36 +423,67 @@ M.indent = function(config, node, state)
420423

421424
local indent_marker = config.indent_marker or ""
422425
local last_indent_marker = config.last_indent_marker or ""
423-
424426
skip_marker[level] = node.is_last_child
427+
425428
local indent = {}
426429
if padding > 0 then
427430
table.insert(indent, { text = string.rep(" ", padding) })
428431
end
429432

430-
for i = start_level - 1, level do
431-
local char = ""
432-
local spaces_count = indent_size
433+
for i = 0, level do
433434
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))
438+
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 = ""
447+
end
448+
end
434449

435-
if i > start_level - 1 and not skip_marker[i] or i == level then
436-
spaces_count = spaces_count - 1
437-
char = indent_marker
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
438461
highlight = marker_highlight
439462
if i == level then
440-
local expander = get_expander()
441-
if expander then
442-
char = expander
443-
highlight = expander_highlight
444-
elseif node.is_last_child then
463+
if node.is_last_child then
445464
char = last_indent_marker
446-
spaces_count = spaces_count - (vim.api.nvim_strwidth(last_indent_marker) - 1)
465+
-- proof of concept for extended markers
466+
-- if indent_size > 2 then
467+
-- separator = "─"
468+
-- end
469+
else
470+
char = indent_marker
447471
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
448482
end
449483
end
450484

451485
table.insert(indent, {
452-
text = char .. string.rep(" ", spaces_count),
486+
text = char .. separator .. additional_spaces,
453487
highlight = highlight,
454488
no_next_padding = true,
455489
})
@@ -458,7 +492,7 @@ M.indent = function(config, node, state)
458492
return indent
459493
end
460494

461-
local get_header = function (state, label, size)
495+
local get_header = function(state, label, size)
462496
if state.sort and state.sort.label == label then
463497
local icon = state.sort.direction == 1 and "" or ""
464498
size = size - 2
@@ -467,12 +501,12 @@ local get_header = function (state, label, size)
467501
return string.format("%" .. size .. "s ", label)
468502
end
469503

470-
M.file_size = function (config, node, state)
504+
M.file_size = function(config, node, state)
471505
-- Root node gets column labels
472506
if node:get_depth() == 1 then
473507
return {
474508
text = get_header(state, "Size", 12),
475-
highlight = highlights.FILE_STATS_HEADER
509+
highlight = highlights.FILE_STATS_HEADER,
476510
}
477511
end
478512

@@ -490,7 +524,7 @@ M.file_size = function (config, node, state)
490524

491525
return {
492526
text = string.format("%12s ", text),
493-
highlight = config.highlight or highlights.FILE_STATS
527+
highlight = config.highlight or highlights.FILE_STATS,
494528
}
495529
end
496530

@@ -505,7 +539,7 @@ local file_time = function(config, node, state, stat_field)
505539
end
506540
return {
507541
text = get_header(state, label, 20),
508-
highlight = highlights.FILE_STATS_HEADER
542+
highlight = highlights.FILE_STATS_HEADER,
509543
}
510544
end
511545

@@ -515,7 +549,7 @@ local file_time = function(config, node, state, stat_field)
515549
local display = seconds and os.date("%Y-%m-%d %I:%M %p", seconds) or "-"
516550
return {
517551
text = string.format("%20s ", display),
518-
highlight = config.highlight or highlights.FILE_STATS
552+
highlight = config.highlight or highlights.FILE_STATS,
519553
}
520554
end
521555

@@ -538,19 +572,19 @@ M.symlink_target = function(config, node, state)
538572
end
539573
end
540574

541-
M.type = function (config, node, state)
575+
M.type = function(config, node, state)
542576
local text = node.ext or node.type
543577
-- Root node gets column labels
544578
if node:get_depth() == 1 then
545579
return {
546580
text = get_header(state, "Type", 10),
547-
highlight = highlights.FILE_STATS_HEADER
581+
highlight = highlights.FILE_STATS_HEADER,
548582
}
549583
end
550584

551585
return {
552586
text = string.format("%10s ", text),
553-
highlight = highlights.FILE_STATS
587+
highlight = highlights.FILE_STATS,
554588
}
555589
end
556590

0 commit comments

Comments
 (0)