* 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 --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
@@ -60,6 +60,7 @@ function Builder:new()
|
||||
lines = {},
|
||||
markers = {},
|
||||
signs = {},
|
||||
extmarks = {},
|
||||
}
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
@@ -228,6 +229,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
|
||||
|
||||
@@ -18,7 +18,7 @@ local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
|
||||
---@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,6 +38,15 @@ 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
|
||||
for i, extname in pairs(extmarks) do
|
||||
for _, mark in ipairs(extname) do
|
||||
vim.api.nvim_buf_set_extmark(bufnr, namespace_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)
|
||||
@@ -67,7 +76,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)
|
||||
|
||||
Reference in New Issue
Block a user