mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-21 23:14:54 +01:00
fix(neotree): back at depth 1 but custom indent
can i get it to render at depth 0?
This commit is contained in:
parent
134a1b6f00
commit
e56436d9df
2 changed files with 87 additions and 20 deletions
|
@ -110,14 +110,16 @@ end
|
|||
M.update_state = function(state)
|
||||
---@type Item[]
|
||||
local root = {
|
||||
id = "codemp",
|
||||
name = "codemp",
|
||||
type = "title",
|
||||
extra = {},
|
||||
children = {},
|
||||
{
|
||||
id = "codemp",
|
||||
name = "codemp",
|
||||
type = "title",
|
||||
extra = {},
|
||||
}
|
||||
}
|
||||
|
||||
if codemp.workspace ~= nil then
|
||||
table.insert(root, spacer())
|
||||
local ws_section = new_root("session #" .. codemp.workspace.name)
|
||||
for i, path in ipairs(codemp.workspace:filetree()) do
|
||||
table.insert(ws_section.children, new_item(codemp.workspace.name, path))
|
||||
|
@ -129,31 +131,30 @@ M.update_state = function(state)
|
|||
end
|
||||
table.insert(ws_section.children, spacer())
|
||||
table.insert(ws_section.children, usr_section)
|
||||
table.insert(root.children, spacer())
|
||||
table.insert(root.children, ws_section)
|
||||
table.insert(root, ws_section)
|
||||
end
|
||||
|
||||
if codemp.client ~= nil then
|
||||
table.insert(root, spacer())
|
||||
local ws_section = new_root("workspaces")
|
||||
for _, ws in ipairs(codemp.available) do
|
||||
table.insert(ws_section.children, new_workspace(ws.name, ws.owned))
|
||||
end
|
||||
table.insert(root.children, spacer())
|
||||
table.insert(root.children, ws_section)
|
||||
table.insert(root, ws_section)
|
||||
|
||||
table.insert(root, spacer())
|
||||
local status_section = new_root("client")
|
||||
table.insert(status_section.children, new_entry("id", codemp.client.id))
|
||||
table.insert(status_section.children, new_entry("name", codemp.client.username))
|
||||
table.insert(root.children, spacer())
|
||||
table.insert(root.children, status_section)
|
||||
table.insert(root, status_section)
|
||||
end
|
||||
|
||||
if codemp.client == nil then
|
||||
table.insert(root.children, spacer())
|
||||
table.insert(root.children, new_button("[connect]"))
|
||||
table.insert(root, spacer())
|
||||
table.insert(root, new_button("[connect]"))
|
||||
end
|
||||
|
||||
renderer.show_nodes({ root }, state)
|
||||
renderer.show_nodes(root, state)
|
||||
for _, node in ipairs(state.tree:get_nodes()) do
|
||||
node:expand()
|
||||
end
|
||||
|
|
|
@ -21,9 +21,9 @@ M.icon = function(config, node, state)
|
|||
local icon, highlight
|
||||
if node.type == "buffer" then
|
||||
if codemp_buffers.map_rev[node.name] ~= nil then
|
||||
icon = "+ "
|
||||
icon = ">"
|
||||
else
|
||||
icon = "- "
|
||||
icon = "+"
|
||||
end
|
||||
highlight = highlights.FILE_ICON
|
||||
elseif node.type == "directory" then
|
||||
|
@ -31,13 +31,13 @@ M.icon = function(config, node, state)
|
|||
highlight = highlights.DIRECTORY_ICON
|
||||
elseif node.type == "root" then
|
||||
if node:is_expanded() then
|
||||
icon = "| "
|
||||
icon = "┬"
|
||||
else
|
||||
icon = "> "
|
||||
icon = "─"
|
||||
end
|
||||
highlight = highlights.DIRECTORY_ICON
|
||||
elseif node.type == "workspace" then
|
||||
icon = "* "
|
||||
icon = "*"
|
||||
if node.extra.owned then
|
||||
highlight = highlights.GIT_STAGED
|
||||
else
|
||||
|
@ -50,7 +50,7 @@ M.icon = function(config, node, state)
|
|||
icon = "$"
|
||||
highlight = highlights.GIT_STAGED
|
||||
elseif node.type == "button" then
|
||||
icon = " "
|
||||
icon = " "
|
||||
highlight = highlights.NORMAL
|
||||
end
|
||||
|
||||
|
@ -100,4 +100,70 @@ M.users = function(config, node, state)
|
|||
return out
|
||||
end
|
||||
|
||||
|
||||
-- this is basically copy-pasted from neo-tree source to remove the 0-depth case
|
||||
-- https://github.com/nvim-neo-tree/neo-tree.nvim/blob/0774fa2085c62a147fcc7b56f0ac37053cc80217/lua/neo-tree/sources/common/components.lua#L383
|
||||
M.indent = function(config, node, state)
|
||||
if not state.skip_marker_at_level then
|
||||
state.skip_marker_at_level = {}
|
||||
end
|
||||
|
||||
local strlen = vim.fn.strdisplaywidth
|
||||
local skip_marker = state.skip_marker_at_level
|
||||
local indent_size = config.indent_size or 2
|
||||
local padding = config.padding or 0
|
||||
local level = node.level
|
||||
local with_markers = config.with_markers
|
||||
local with_expanders = config.with_expanders == nil and file_nesting.is_enabled()
|
||||
or config.with_expanders
|
||||
local marker_highlight = config.highlight or highlights.INDENT_MARKER
|
||||
local expander_highlight = config.expander_highlight or config.highlight or highlights.EXPANDER
|
||||
|
||||
local function get_expander()
|
||||
if with_expanders and utils.is_expandable(node) then
|
||||
return node:is_expanded() and (config.expander_expanded or "")
|
||||
or (config.expander_collapsed or "")
|
||||
end
|
||||
end
|
||||
|
||||
local indent_marker = config.indent_marker or "│"
|
||||
local last_indent_marker = config.last_indent_marker or "└"
|
||||
|
||||
skip_marker[level] = node.is_last_child
|
||||
local indent = {}
|
||||
if padding > 0 then
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(indent, {
|
||||
text = char .. string.rep(" ", spaces_count),
|
||||
highlight = highlight,
|
||||
no_next_padding = true,
|
||||
})
|
||||
end
|
||||
|
||||
return indent
|
||||
end
|
||||
|
||||
return vim.tbl_deep_extend("force", common, M)
|
||||
|
|
Loading…
Reference in a new issue