add padding first column
This commit is contained in:
parent
64e2192f52
commit
7c0f7e906a
@ -58,18 +58,18 @@ local Builder = Class:extend()
|
|||||||
---@protected
|
---@protected
|
||||||
---@param args BuilderArgs
|
---@param args BuilderArgs
|
||||||
function Builder:new(args)
|
function Builder:new(args)
|
||||||
self.explorer = args.explorer
|
self.explorer = args.explorer
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.depth = 0
|
self.depth = 0
|
||||||
self.hl_range_args = {}
|
self.hl_range_args = {}
|
||||||
self.combined_groups = {}
|
self.combined_groups = {}
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
self.markers = {}
|
self.markers = {}
|
||||||
self.signs = {}
|
self.signs = {}
|
||||||
self.extmarks = {}
|
self.extmarks = {}
|
||||||
self.virtual_lines = {}
|
self.virtual_lines = {}
|
||||||
self.decorators = {}
|
self.decorators = {}
|
||||||
self.hidden_display = Builder:setup_hidden_display_function(self.explorer.opts)
|
self.hidden_display = Builder:setup_hidden_display_function(self.explorer.opts)
|
||||||
|
|
||||||
-- instantiate all the builtin and user decorator instances
|
-- instantiate all the builtin and user decorator instances
|
||||||
local builtin, user
|
local builtin, user
|
||||||
@ -101,7 +101,7 @@ end
|
|||||||
---@param end_ number|nil
|
---@param end_ number|nil
|
||||||
function Builder:insert_highlight(groups, start, end_)
|
function Builder:insert_highlight(groups, start, end_)
|
||||||
for _, higroup in ipairs(groups) do
|
for _, higroup in ipairs(groups) do
|
||||||
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start, }, finish = { self.index, end_ or -1, } })
|
table.insert(self.hl_range_args, { higroup = higroup, start = { self.index, start }, finish = { self.index, end_ or -1 } })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ function Builder:add_hidden_count_string(node, idx, num_children)
|
|||||||
-- if we change the traversal, we might need to sort by depth before rendering `self.virtual_lines`
|
-- if we change the traversal, we might need to sort by depth before rendering `self.virtual_lines`
|
||||||
-- to maintain proper ordering of parent and child folder hidden count info.
|
-- to maintain proper ordering of parent and child folder hidden count info.
|
||||||
table.insert(self.virtual_lines[line_nr], {
|
table.insert(self.virtual_lines[line_nr], {
|
||||||
{ indent_string, indent_markers.hl },
|
{ indent_string, indent_markers.hl },
|
||||||
{ string.rep(indent_padding, (node.parent == nil and 0 or 1)) .. hidden_count_string, "NvimTreeHiddenDisplay" },
|
{ string.rep(indent_padding, (node.parent == nil and 0 or 1)) .. hidden_count_string, "NvimTreeHiddenDisplay" },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -381,8 +381,28 @@ end
|
|||||||
function Builder:build_header()
|
function Builder:build_header()
|
||||||
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
if view.is_root_folder_visible(self.explorer.absolute_path) then
|
||||||
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label)
|
||||||
table.insert(self.lines, root_name)
|
|
||||||
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name))
|
-- Pad to window width so the highlight spans the whole row.
|
||||||
|
local win = view.get_winnr()
|
||||||
|
local width = 0
|
||||||
|
if win and vim.api.nvim_win_is_valid(win) then
|
||||||
|
width = vim.api.nvim_win_get_width(win)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Use display width for proper padding with Nerd Font / wide glyphs.
|
||||||
|
local name_display_w = vim.fn.strdisplaywidth(root_name)
|
||||||
|
local pad = 0
|
||||||
|
if width and width > name_display_w then
|
||||||
|
pad = width - name_display_w
|
||||||
|
end
|
||||||
|
|
||||||
|
local padded_root = pad > 0 and (root_name .. string.rep(" ", pad)) or root_name
|
||||||
|
|
||||||
|
table.insert(self.lines, padded_root)
|
||||||
|
-- Highlight the entire padded string (covers the full visible row)
|
||||||
|
self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(padded_root))
|
||||||
|
|
||||||
|
-- Keep original indexing behavior
|
||||||
self.index = 1
|
self.index = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -390,12 +410,11 @@ function Builder:build_header()
|
|||||||
local filter_line = string.format("%s/%s/", self.explorer.opts.live_filter.prefix, self.explorer.live_filter.filter)
|
local filter_line = string.format("%s/%s/", self.explorer.opts.live_filter.prefix, self.explorer.live_filter.filter)
|
||||||
table.insert(self.lines, filter_line)
|
table.insert(self.lines, filter_line)
|
||||||
local prefix_length = string.len(self.explorer.opts.live_filter.prefix)
|
local prefix_length = string.len(self.explorer.opts.live_filter.prefix)
|
||||||
self:insert_highlight({ "NvimTreeLiveFilterPrefix" }, 0, prefix_length)
|
self:insert_highlight({ "NvimTreeLiveFilterPrefix" }, 0, prefix_length)
|
||||||
self:insert_highlight({ "NvimTreeLiveFilterValue" }, prefix_length, string.len(filter_line))
|
self:insert_highlight({ "NvimTreeLiveFilterValue" }, prefix_length, string.len(filter_line))
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Sanitize lines for rendering.
|
---Sanitize lines for rendering.
|
||||||
---Replace newlines with literal \n
|
---Replace newlines with literal \n
|
||||||
---@private
|
---@private
|
||||||
@ -439,17 +458,18 @@ function Builder:setup_hidden_display_function(opts)
|
|||||||
-- In case of missing field such as live_filter we zero it, otherwise keep field as is
|
-- In case of missing field such as live_filter we zero it, otherwise keep field as is
|
||||||
hidden_stats = vim.tbl_deep_extend("force", {
|
hidden_stats = vim.tbl_deep_extend("force", {
|
||||||
live_filter = 0,
|
live_filter = 0,
|
||||||
git = 0,
|
git = 0,
|
||||||
buf = 0,
|
buf = 0,
|
||||||
dotfile = 0,
|
dotfile = 0,
|
||||||
custom = 0,
|
custom = 0,
|
||||||
bookmark = 0,
|
bookmark = 0,
|
||||||
}, hidden_stats or {})
|
}, hidden_stats or {})
|
||||||
|
|
||||||
local ok, result = pcall(hidden_display, hidden_stats)
|
local ok, result = pcall(hidden_display, hidden_stats)
|
||||||
if not ok then
|
if not ok then
|
||||||
notify.warn(
|
notify.warn(
|
||||||
"Problem occurred in the function ``opts.renderer.hidden_display`` see nvim-tree.renderer.hidden_display on :h nvim-tree")
|
"Problem occurred in the function ``opts.renderer.hidden_display`` see nvim-tree.renderer.hidden_display on :h nvim-tree"
|
||||||
|
)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
|
|||||||
@ -22,8 +22,8 @@ local function check_siblings_for_folder(node, with_arrows)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, inline_arrows, node, early_stop)
|
local function get_padding_indent_markers(depth, idx, nodes_number, markers, with_arrows, inline_arrows, node, early_stop)
|
||||||
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or ""
|
local base_padding = with_arrows and (not node.nodes or depth > 0) and " " or " "
|
||||||
local padding = (inline_arrows or depth == 0) and base_padding or ""
|
local padding = (inline_arrows or depth == 0) and base_padding or " "
|
||||||
|
|
||||||
if depth > 0 then
|
if depth > 0 then
|
||||||
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
|
local has_folder_sibling = check_siblings_for_folder(node, with_arrows)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user