* feat(#1079): add highlight NvimTreeCopiedText and NvimTreeCutText * feat(#1079): add highlight NvimTreeCopiedText and NvimTreeCutText * feat(#1079): node may not be present in copy and cut * feat(#2411): bookmark highlight and icon placement * feat(#1079): add renderer.highlight_clipboard * feat(#1079): add renderer.highlight_clipboard * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * style * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement * feat(#2411): bookmark highlight and icon placement
This commit is contained in:
committed by
GitHub
parent
ea147418e0
commit
d49a284236
@@ -6,6 +6,7 @@ local pad = require "nvim-tree.renderer.components.padding"
|
||||
local icons = require "nvim-tree.renderer.components.icons"
|
||||
local modified = require "nvim-tree.renderer.components.modified"
|
||||
local diagnostics = require "nvim-tree.renderer.components.diagnostics"
|
||||
local bookmarks = require "nvim-tree.renderer.components.bookmarks"
|
||||
|
||||
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
|
||||
|
||||
@@ -83,6 +84,14 @@ function Builder:configure_diagnostics_icon_placement(where)
|
||||
return self
|
||||
end
|
||||
|
||||
function Builder:configure_bookmark_icon_placement(where)
|
||||
if where ~= "after" and where ~= "before" and where ~= "signcolumn" then
|
||||
where = "before" -- default before
|
||||
end
|
||||
self.bookmarks_placement = where
|
||||
return self
|
||||
end
|
||||
|
||||
function Builder:configure_modified_placement(where)
|
||||
if where ~= "after" and where ~= "before" and where ~= "signcolumn" then
|
||||
where = "after" -- default after
|
||||
@@ -245,12 +254,21 @@ function Builder:_get_modified_icon(node)
|
||||
return modified_icon
|
||||
end
|
||||
|
||||
---@param node table
|
||||
---@return HighlightedString[]|nil icon
|
||||
function Builder:_get_bookmark_icon(node)
|
||||
local bookmark_icon = bookmarks.get_icon(node)
|
||||
if bookmark_icon and self.bookmarks_placement == "signcolumn" then
|
||||
table.insert(self.signs, { sign = bookmark_icon.hl[1], lnum = self.index + 1, priority = 4 })
|
||||
bookmark_icon = nil
|
||||
end
|
||||
return bookmark_icon
|
||||
end
|
||||
|
||||
---@param node table
|
||||
---@return string|nil icon_hl
|
||||
---@return string|nil name_hl
|
||||
function Builder:_get_highlight_override(node, unloaded_bufnr)
|
||||
-- highlights precedence:
|
||||
-- original < git < opened_file < modified
|
||||
local name_hl, icon_hl
|
||||
|
||||
-- git
|
||||
@@ -311,8 +329,18 @@ end
|
||||
---@param git_icons HighlightedString[]|nil
|
||||
---@param diagnostics_icon HighlightedString|nil
|
||||
---@param modified_icon HighlightedString|nil
|
||||
---@param bookmark_icon HighlightedString|nil
|
||||
---@return HighlightedString[]
|
||||
function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon)
|
||||
function Builder:_format_line(
|
||||
indent_markers,
|
||||
arrows,
|
||||
icon,
|
||||
name,
|
||||
git_icons,
|
||||
diagnostics_icon,
|
||||
modified_icon,
|
||||
bookmark_icon
|
||||
)
|
||||
local added_len = 0
|
||||
local function add_to_end(t1, t2)
|
||||
for _, v in ipairs(t2) do
|
||||
@@ -341,6 +369,9 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
|
||||
if diagnostics_icon and self.diagnostics_placement == "before" then
|
||||
add_to_end(line, { diagnostics_icon })
|
||||
end
|
||||
if bookmark_icon and self.bookmarks_placement == "before" then
|
||||
add_to_end(line, { bookmark_icon })
|
||||
end
|
||||
|
||||
add_to_end(line, { name })
|
||||
|
||||
@@ -353,6 +384,9 @@ function Builder:_format_line(indent_markers, arrows, icon, name, git_icons, dia
|
||||
if diagnostics_icon and self.diagnostics_placement == "after" then
|
||||
add_to_end(line, { diagnostics_icon })
|
||||
end
|
||||
if bookmark_icon and self.bookmarks_placement == "after" then
|
||||
add_to_end(line, { bookmark_icon })
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
@@ -363,6 +397,9 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
|
||||
-- various components
|
||||
local indent_markers = pad.get_indent_markers(self.depth, idx, num_children, node, self.markers)
|
||||
local arrows = pad.get_arrows(node)
|
||||
|
||||
-- adds icons to signcolumn
|
||||
local bookmark_icon = self:_get_bookmark_icon(node)
|
||||
local git_icons = self:_get_git_icons(node)
|
||||
local modified_icon = self:_get_modified_icon(node)
|
||||
local diagnostics_icon = self:_get_diagnostics_icon(node)
|
||||
@@ -389,10 +426,12 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
|
||||
end
|
||||
|
||||
-- extra highighting
|
||||
self:_append_highlight(node, bookmarks.get_highlight, icon.hl, name.hl)
|
||||
self:_append_highlight(node, diagnostics.get_highlight, icon.hl, name.hl)
|
||||
self:_append_highlight(node, copy_paste.get_highlight, icon.hl, name.hl)
|
||||
|
||||
local line = self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon)
|
||||
local line =
|
||||
self:_format_line(indent_markers, arrows, icon, name, git_icons, diagnostics_icon, modified_icon, bookmark_icon)
|
||||
self:_insert_line(self:_unwrap_highlighted_strings(line))
|
||||
|
||||
self.index = self.index + 1
|
||||
|
||||
Reference in New Issue
Block a user