* feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api * feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api * feat(icon_placement): consolidate doc * fix: extra namespace added to avoid colision between right_align and full_name features * style: rename namespace_id --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
82ba116bbd
commit
48d0e82f94
@ -955,6 +955,12 @@ Configuration options for icons.
|
||||
Icon order and sign column precedence:
|
||||
git < hidden < modified < bookmarked < diagnostics
|
||||
|
||||
`renderer.icons.*_placement` options may be:
|
||||
- `"before"` : before file/folder, after the file/folders icons
|
||||
- `"after"` : after file/folder
|
||||
- `"signcolumn"` : far left, requires |nvim-tree.view.signcolumn| enabled
|
||||
- `"right_align"` : far right
|
||||
|
||||
*nvim-tree.renderer.icons.web_devicons*
|
||||
Configure optional plugin `"nvim-tree/nvim-web-devicons"`
|
||||
|
||||
@ -983,33 +989,23 @@ Icon order and sign column precedence:
|
||||
Type: `boolean`, Default: `true`
|
||||
|
||||
*nvim-tree.renderer.icons.git_placement*
|
||||
Place where the git icons will be rendered.
|
||||
Can be `"after"` or `"before"` filename (after the file/folders icons)
|
||||
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
|
||||
Git icons placement.
|
||||
Type: `string`, Default: `"before"`
|
||||
|
||||
*nvim-tree.renderer.icons.diagnostics_placement*
|
||||
Place where the diagnostics icon will be rendered.
|
||||
Can be `"after"` or `"before"` filename (after the file/folders icons)
|
||||
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
|
||||
Diganostic icon placement.
|
||||
Type: `string`, Default: `"signcolumn"`
|
||||
|
||||
*nvim-tree.renderer.icons.modified_placement*
|
||||
Place where the modified icon will be rendered.
|
||||
Can be `"after"` or `"before"` filename (after the file/folders icons)
|
||||
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
|
||||
Modified icon placement.
|
||||
Type: `string`, Default: `"after"`
|
||||
|
||||
*nvim-tree.renderer.icons.hidden_placement*
|
||||
Place where the hidden (dotfile) icon will be rendered.
|
||||
Can be `"after"` or `"before"` filename (after the file/folders icons)
|
||||
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
|
||||
Hidden icon placement.
|
||||
Type: `string`, Default: `"after"`
|
||||
|
||||
*nvim-tree.renderer.icons.bookmarks_placement*
|
||||
Place where the bookmarks icon will be rendered.
|
||||
Can be `"after"` or `"before"` filename (after the file/folders icons)
|
||||
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
|
||||
Bookmark icon placement.
|
||||
Type: `string`, Default: `signcolumn`
|
||||
|
||||
*nvim-tree.renderer.icons.padding*
|
||||
|
||||
@ -688,11 +688,11 @@ local ACCEPTED_STRINGS = {
|
||||
highlight_diagnostics = { "none", "icon", "name", "all" },
|
||||
highlight_clipboard = { "none", "icon", "name", "all" },
|
||||
icons = {
|
||||
git_placement = { "before", "after", "signcolumn" },
|
||||
modified_placement = { "before", "after", "signcolumn" },
|
||||
hidden_placement = { "before", "after", "signcolumn" },
|
||||
diagnostics_placement = { "before", "after", "signcolumn" },
|
||||
bookmarks_placement = { "before", "after", "signcolumn" },
|
||||
git_placement = { "before", "after", "signcolumn", "right_align" },
|
||||
modified_placement = { "before", "after", "signcolumn", "right_align" },
|
||||
hidden_placement = { "before", "after", "signcolumn", "right_align" },
|
||||
diagnostics_placement = { "before", "after", "signcolumn", "right_align" },
|
||||
bookmarks_placement = { "before", "after", "signcolumn", "right_align" },
|
||||
},
|
||||
},
|
||||
help = {
|
||||
|
||||
@ -16,6 +16,7 @@ M.ICON_PLACEMENT = {
|
||||
signcolumn = 1,
|
||||
before = 2,
|
||||
after = 3,
|
||||
right_align = 4,
|
||||
}
|
||||
|
||||
return M
|
||||
|
||||
@ -61,6 +61,7 @@ function Builder:new()
|
||||
lines = {},
|
||||
markers = {},
|
||||
signs = {},
|
||||
extmarks = {},
|
||||
}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
@ -229,6 +230,14 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
|
||||
add_to_end(line, M.decorators[i]:icons_after(node))
|
||||
end
|
||||
|
||||
local rights = {}
|
||||
for i = #M.decorators, 1, -1 do
|
||||
add_to_end(rights, M.decorators[i]:icons_right_align(node))
|
||||
end
|
||||
if #rights > 0 then
|
||||
self.extmarks[self.index] = rights
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
|
||||
@ -74,6 +74,17 @@ function Decorator:icons_after(node)
|
||||
return self:calculate_icons(node)
|
||||
end
|
||||
|
||||
---Icons when ICON_PLACEMENT.right_align
|
||||
---@param node Node
|
||||
---@return HighlightedString[]|nil icons
|
||||
function Decorator:icons_right_align(node)
|
||||
if not self.enabled or self.icon_placement ~= ICON_PLACEMENT.right_align then
|
||||
return
|
||||
end
|
||||
|
||||
return self:calculate_icons(node)
|
||||
end
|
||||
|
||||
---Maybe icons, optionally implemented
|
||||
---@protected
|
||||
---@param _ Node
|
||||
|
||||
@ -12,13 +12,14 @@ local M = {}
|
||||
|
||||
local SIGN_GROUP = "NvimTreeRendererSigns"
|
||||
|
||||
local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
|
||||
local namespace_highlights_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
|
||||
local namespace_extmarks_id = vim.api.nvim_create_namespace "NvimTreeExtmarks"
|
||||
|
||||
---@param bufnr number
|
||||
---@param lines string[]
|
||||
---@param hl_args AddHighlightArgs[]
|
||||
---@param signs string[]
|
||||
local function _draw(bufnr, lines, hl_args, signs)
|
||||
local function _draw(bufnr, lines, hl_args, signs, extmarks)
|
||||
if vim.fn.has "nvim-0.10" == 1 then
|
||||
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
|
||||
else
|
||||
@ -38,17 +39,28 @@ local function _draw(bufnr, lines, hl_args, signs)
|
||||
for i, sign_name in pairs(signs) do
|
||||
vim.fn.sign_place(0, SIGN_GROUP, sign_name, bufnr, { lnum = i + 1 })
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_extmarks_id, 0, -1)
|
||||
for i, extname in pairs(extmarks) do
|
||||
for _, mark in ipairs(extname) do
|
||||
vim.api.nvim_buf_set_extmark(bufnr, namespace_extmarks_id, i, -1, {
|
||||
virt_text = { { mark.str, mark.hl } },
|
||||
virt_text_pos = "right_align",
|
||||
hl_mode = "combine",
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.render_hl(bufnr, hl)
|
||||
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
|
||||
return
|
||||
end
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
|
||||
for _, data in ipairs(hl) do
|
||||
if type(data[1]) == "table" then
|
||||
for _, group in ipairs(data[1]) do
|
||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_id, group, data[2], data[3], data[4])
|
||||
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -67,7 +79,7 @@ function M.draw()
|
||||
|
||||
local builder = Builder:new():build()
|
||||
|
||||
_draw(bufnr, builder.lines, builder.hl_args, builder.signs)
|
||||
_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks)
|
||||
|
||||
if cursor and #builder.lines >= cursor[1] then
|
||||
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user