feat(#2948): decorator classes specified by prefix rather than suffix
This commit is contained in:
parent
4bf4a85b9f
commit
3b60fa7dfa
@ -929,7 +929,7 @@ Whether to show the destination of the symlink.
|
||||
*nvim-tree.renderer.decorators*
|
||||
Highlighting and icons for the nodes, in increasing order of precedence.
|
||||
Uses strings to specify builtin decorators otherwise specify your
|
||||
`nvim_tree.api.decorator.DecoratorUser` class.
|
||||
`nvim_tree.api.decorator.UserDecorator` class.
|
||||
Type: `nvim_tree.api.decorator.Name[]`, Default: >lua
|
||||
{
|
||||
"Git",
|
||||
@ -2777,7 +2777,7 @@ Decorators may:
|
||||
- Set highlight group for the name or icons
|
||||
- Override node icon
|
||||
|
||||
Create your decorator class via `api.decorator.DecoratorUser:extend()` and add it
|
||||
Create your decorator class via `api.decorator.UserDecorator:extend()` and add it
|
||||
to |nvim-tree.renderer.decorators|
|
||||
|
||||
e.g. default decorators with an user decorator being overridden only by Cut: >lua
|
||||
@ -2798,9 +2798,9 @@ See `api_decorator.lua` for decorator class definition and full documentation.
|
||||
Example decorator: >lua
|
||||
|
||||
---Create your decorator class
|
||||
---@class (exact) MyDecorator: nvim_tree.api.decorator.DecoratorUser
|
||||
---@class (exact) MyDecorator: nvim_tree.api.decorator.UserDecorator
|
||||
---@field private my_icon nvim_tree.api.HighlightedString
|
||||
local MyDecorator = require("nvim-tree.api").decorator.DecoratorUser:extend()
|
||||
local MyDecorator = require("nvim-tree.api").decorator.UserDecorator:extend()
|
||||
|
||||
---Mandatory constructor :new() will be called once per tree render, with no arguments.
|
||||
function MyDecorator:new()
|
||||
|
||||
@ -284,7 +284,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
special_files = { "Cargo.toml", "Makefile", "README.md", "readme.md" },
|
||||
hidden_display = "none",
|
||||
symlink_destination = true,
|
||||
decorators = { "Git", "Opened", "Hidden", "Modified", "Bookmarks", "Diagnostics", "Copied", "Cut", },
|
||||
decorators = { "Git", "Open", "Hidden", "Modified", "Bookmark", "Diagnostics", "Copied", "Cut", },
|
||||
highlight_git = "none",
|
||||
highlight_diagnostics = "none",
|
||||
highlight_opened_files = "none",
|
||||
|
||||
@ -10,11 +10,11 @@ local nvim_tree = {}
|
||||
---@alias nvim_tree.api.decorator.IconPlacement "none" | "before" | "after" | "signcolumn" | "right_align"
|
||||
|
||||
---Names of builtin decorators or your decorator classes. Builtins are ordered lowest to highest priority.
|
||||
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.DecoratorUser
|
||||
---@alias nvim_tree.api.decorator.Name "Git" | "Opened" | "Hidden" | "Modified" | "Bookmarks" | "Diagnostics" | "Copied" | "Cut" | nvim_tree.api.decorator.UserDecorator
|
||||
|
||||
---Custom decorator, see :help nvim-tree-decorators
|
||||
---
|
||||
---@class (exact) nvim_tree.api.decorator.DecoratorUser
|
||||
---@class (exact) nvim_tree.api.decorator.UserDecorator
|
||||
---@field protected enabled boolean
|
||||
---@field protected highlight_range nvim_tree.api.decorator.HighlightRange
|
||||
---@field protected icon_placement nvim_tree.api.decorator.IconPlacement
|
||||
@ -22,28 +22,28 @@ local nvim_tree = {}
|
||||
---Abstract: no-args constructor must be implemented and will be called once per tree render.
|
||||
---Must set all fields.
|
||||
---
|
||||
function nvim_tree.api.decorator.DecoratorUser:new() end
|
||||
function nvim_tree.api.decorator.UserDecorator:new() end
|
||||
|
||||
---Abstract: optionally implement to set the node's icon
|
||||
---
|
||||
---@param node nvim_tree.api.Node
|
||||
---@return nvim_tree.api.HighlightedString? icon_node
|
||||
function nvim_tree.api.decorator.DecoratorUser:icon_node(node) end
|
||||
function nvim_tree.api.decorator.UserDecorator:icon_node(node) end
|
||||
|
||||
---Abstract: optionally implement to provide icons and the highlight groups for your icon_placement.
|
||||
---
|
||||
---@param node nvim_tree.api.Node
|
||||
---@return nvim_tree.api.HighlightedString[]? icons
|
||||
function nvim_tree.api.decorator.DecoratorUser:icons(node) end
|
||||
function nvim_tree.api.decorator.UserDecorator:icons(node) end
|
||||
|
||||
---Abstract: optionally implement to provide one highlight group to apply to your highlight_range.
|
||||
---
|
||||
---@param node nvim_tree.api.Node
|
||||
---@return string? highlight_group
|
||||
function nvim_tree.api.decorator.DecoratorUser:highlight_group(node) end
|
||||
function nvim_tree.api.decorator.UserDecorator:highlight_group(node) end
|
||||
|
||||
---Define a sign. This should be called in the constructor.
|
||||
---
|
||||
---@protected
|
||||
---@param icon nvim_tree.api.HighlightedString?
|
||||
function nvim_tree.api.decorator.DecoratorUser:define_sign(icon) end
|
||||
function nvim_tree.api.decorator.UserDecorator:define_sign(icon) end
|
||||
|
||||
@ -11,7 +11,7 @@ local notify = require("nvim-tree.notify")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
local FileLinkNode = require("nvim-tree.node.file-link")
|
||||
local RootNode = require("nvim-tree.node.root")
|
||||
local DecoratorUser = require("nvim-tree.renderer.decorator.user")
|
||||
local UserDecorator = require("nvim-tree.renderer.decorator.user")
|
||||
|
||||
local Api = {
|
||||
tree = {},
|
||||
@ -314,7 +314,7 @@ Api.commands.get = wrap(function()
|
||||
end)
|
||||
|
||||
---Create a decorator class by calling :extend()
|
||||
---@type nvim_tree.api.decorator.DecoratorUser
|
||||
Api.decorator.DecoratorUser = DecoratorUser --[[@as nvim_tree.api.decorator.DecoratorUser]]
|
||||
---@type nvim_tree.api.decorator.UserDecorator
|
||||
Api.decorator.UserDecorator = UserDecorator --[[@as nvim_tree.api.decorator.UserDecorator]]
|
||||
|
||||
return Api
|
||||
|
||||
@ -6,15 +6,15 @@ local Class = require("nvim-tree.classic")
|
||||
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
local DecoratorBookmarks = require("nvim-tree.renderer.decorator.bookmarks")
|
||||
local DecoratorCopied = require("nvim-tree.renderer.decorator.copied")
|
||||
local DecoratorCut = require("nvim-tree.renderer.decorator.cut")
|
||||
local DecoratorDiagnostics = require("nvim-tree.renderer.decorator.diagnostics")
|
||||
local DecoratorGit = require("nvim-tree.renderer.decorator.git")
|
||||
local DecoratorHidden = require("nvim-tree.renderer.decorator.hidden")
|
||||
local DecoratorModified = require("nvim-tree.renderer.decorator.modified")
|
||||
local DecoratorOpened = require("nvim-tree.renderer.decorator.opened")
|
||||
local DecoratorUser = require("nvim-tree.renderer.decorator.user")
|
||||
local BookmarkDecorator = require("nvim-tree.renderer.decorator.bookmarks")
|
||||
local CopiedDecorator = require("nvim-tree.renderer.decorator.copied")
|
||||
local CutDecorator = require("nvim-tree.renderer.decorator.cut")
|
||||
local DiagnosticsDecorator = require("nvim-tree.renderer.decorator.diagnostics")
|
||||
local GitDecorator = require("nvim-tree.renderer.decorator.git")
|
||||
local HiddenDecorator = require("nvim-tree.renderer.decorator.hidden")
|
||||
local ModifiedDecorator = require("nvim-tree.renderer.decorator.modified")
|
||||
local OpenDecorator = require("nvim-tree.renderer.decorator.opened")
|
||||
local UserDecorator = require("nvim-tree.renderer.decorator.user")
|
||||
|
||||
local pad = require("nvim-tree.renderer.components.padding")
|
||||
|
||||
@ -23,14 +23,14 @@ local pad = require("nvim-tree.renderer.components.padding")
|
||||
-- Builtin Decorators
|
||||
---@type table<nvim_tree.api.decorator.Name, Decorator>
|
||||
local BUILTIN_DECORATORS = {
|
||||
Git = DecoratorGit,
|
||||
Opened = DecoratorOpened,
|
||||
Hidden = DecoratorHidden,
|
||||
Modified = DecoratorModified,
|
||||
Bookmarks = DecoratorBookmarks,
|
||||
Diagnostics = DecoratorDiagnostics,
|
||||
Copied = DecoratorCopied,
|
||||
Cut = DecoratorCut,
|
||||
Git = GitDecorator,
|
||||
Open = OpenDecorator,
|
||||
Hidden = HiddenDecorator,
|
||||
Modified = ModifiedDecorator,
|
||||
Bookmark = BookmarkDecorator,
|
||||
Diagnostics = DiagnosticsDecorator,
|
||||
Copied = CopiedDecorator,
|
||||
Cut = CutDecorator,
|
||||
}
|
||||
|
||||
---@class (exact) AddHighlightArgs
|
||||
@ -83,8 +83,8 @@ function Builder:new(args)
|
||||
---@type Decorator
|
||||
builtin = BUILTIN_DECORATORS[d]
|
||||
|
||||
---@type DecoratorUser
|
||||
user = d.as and d:as(DecoratorUser)
|
||||
---@type UserDecorator
|
||||
user = d.as and d:as(UserDecorator)
|
||||
|
||||
if builtin then
|
||||
table.insert(self.decorators, builtin({ explorer = self.explorer }))
|
||||
@ -164,18 +164,18 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
|
||||
add_to_end(line, { icon })
|
||||
|
||||
for _, d in ipairs(self.decorators) do
|
||||
add_to_end(line, d:icons_before(not d:is(DecoratorUser) and node or api_node))
|
||||
add_to_end(line, d:icons_before(not d:is(UserDecorator) and node or api_node))
|
||||
end
|
||||
|
||||
add_to_end(line, { name })
|
||||
|
||||
for _, d in ipairs(self.decorators) do
|
||||
add_to_end(line, d:icons_after(not d:is(DecoratorUser) and node or api_node))
|
||||
add_to_end(line, d:icons_after(not d:is(UserDecorator) and node or api_node))
|
||||
end
|
||||
|
||||
local rights = {}
|
||||
for _, d in ipairs(self.decorators) do
|
||||
add_to_end(rights, d:icons_right_align(not d:is(DecoratorUser) and node or api_node))
|
||||
add_to_end(rights, d:icons_right_align(not d:is(UserDecorator) and node or api_node))
|
||||
end
|
||||
if #rights > 0 then
|
||||
self.extmarks[self.index] = rights
|
||||
@ -194,7 +194,7 @@ function Builder:build_signs(node)
|
||||
local d, sign_name
|
||||
for i = #self.decorators, 1, -1 do
|
||||
d = self.decorators[i]
|
||||
sign_name = d:sign_name(not d:is(DecoratorUser) and node or api_node)
|
||||
sign_name = d:sign_name(not d:is(UserDecorator) and node or api_node)
|
||||
if sign_name then
|
||||
self.signs[self.index] = sign_name
|
||||
break
|
||||
@ -251,9 +251,9 @@ function Builder:icon_name_decorated(node)
|
||||
local hl_icon, hl_name
|
||||
for _, d in ipairs(self.decorators) do
|
||||
-- maybe overridde icon
|
||||
icon = d:icon_node((not d:is(DecoratorUser) and node or api_node)) or icon
|
||||
icon = d:icon_node((not d:is(UserDecorator) and node or api_node)) or icon
|
||||
|
||||
hl_icon, hl_name = d:highlight_group_icon_name((not d:is(DecoratorUser) and node or api_node))
|
||||
hl_icon, hl_name = d:highlight_group_icon_name((not d:is(UserDecorator) and node or api_node))
|
||||
|
||||
table.insert(icon_groups, hl_icon)
|
||||
table.insert(name_groups, hl_name)
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorBookmarks: Decorator
|
||||
---@class (exact) BookmarkDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private icon HighlightedString?
|
||||
local DecoratorBookmarks = Decorator:extend()
|
||||
local BookmarkDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorBookmarks
|
||||
---@overload fun(args: DecoratorArgs): DecoratorBookmarks
|
||||
---@class BookmarkDecorator
|
||||
---@overload fun(args: DecoratorArgs): BookmarkDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorBookmarks:new(args)
|
||||
function BookmarkDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -29,7 +29,7 @@ end
|
||||
---Bookmark icon: renderer.icons.show.bookmarks and node is marked
|
||||
---@param node Node
|
||||
---@return HighlightedString[]? icons
|
||||
function DecoratorBookmarks:icons(node)
|
||||
function BookmarkDecorator:icons(node)
|
||||
if self.explorer.marks:get(node) then
|
||||
return { self.icon }
|
||||
end
|
||||
@ -38,10 +38,10 @@ end
|
||||
---Bookmark highlight: renderer.highlight_bookmarks and node is marked
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorBookmarks:highlight_group(node)
|
||||
function BookmarkDecorator:highlight_group(node)
|
||||
if self.highlight_range ~= "none" and self.explorer.marks:get(node) then
|
||||
return "NvimTreeBookmarkHL"
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorBookmarks
|
||||
return BookmarkDecorator
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorCopied: Decorator
|
||||
---@class (exact) CopiedDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
local DecoratorCopied = Decorator:extend()
|
||||
local CopiedDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorCopied
|
||||
---@overload fun(args: DecoratorArgs): DecoratorCopied
|
||||
---@class CopiedDecorator
|
||||
---@overload fun(args: DecoratorArgs): CopiedDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorCopied:new(args)
|
||||
function CopiedDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -20,10 +20,10 @@ end
|
||||
---Copied highlight: renderer.highlight_clipboard and node is copied
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorCopied:highlight_group(node)
|
||||
function CopiedDecorator:highlight_group(node)
|
||||
if self.highlight_range ~= "none" and self.explorer.clipboard:is_copied(node) then
|
||||
return "NvimTreeCopiedHL"
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorCopied
|
||||
return CopiedDecorator
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorCut: Decorator
|
||||
---@class (exact) CutDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
local DecoratorCut = Decorator:extend()
|
||||
local CutDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorCut
|
||||
---@overload fun(args: DecoratorArgs): DecoratorCut
|
||||
---@class CutDecorator
|
||||
---@overload fun(args: DecoratorArgs): CutDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorCut:new(args)
|
||||
function CutDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -20,10 +20,10 @@ end
|
||||
---Cut highlight: renderer.highlight_clipboard and node is cut
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorCut:highlight_group(node)
|
||||
function CutDecorator:highlight_group(node)
|
||||
if self.highlight_range ~= "none" and self.explorer.clipboard:is_cut(node) then
|
||||
return "NvimTreeCutHL"
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorCut
|
||||
return CutDecorator
|
||||
|
||||
@ -30,17 +30,17 @@ local ICON_KEYS = {
|
||||
["hint"] = vim.diagnostic.severity.HINT,
|
||||
}
|
||||
|
||||
---@class (exact) DecoratorDiagnostics: Decorator
|
||||
---@class (exact) DiagnosticsDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private diag_icons HighlightedString[]?
|
||||
local DecoratorDiagnostics = Decorator:extend()
|
||||
local DiagnosticsDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorDiagnostics
|
||||
---@overload fun(args: DecoratorArgs): DecoratorDiagnostics
|
||||
---@class DiagnosticsDecorator
|
||||
---@overload fun(args: DecoratorArgs): DiagnosticsDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorDiagnostics:new(args)
|
||||
function DiagnosticsDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -62,7 +62,7 @@ end
|
||||
---Diagnostic icon: diagnostics.enable, renderer.icons.show.diagnostics and node has status
|
||||
---@param node Node
|
||||
---@return HighlightedString[]? icons
|
||||
function DecoratorDiagnostics:icons(node)
|
||||
function DiagnosticsDecorator:icons(node)
|
||||
if node and self.diag_icons then
|
||||
local diag_status = diagnostics.get_diag_status(node)
|
||||
local diag_value = diag_status and diag_status.value
|
||||
@ -76,7 +76,7 @@ end
|
||||
---Diagnostic highlight: diagnostics.enable, renderer.highlight_diagnostics and node has status
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorDiagnostics:highlight_group(node)
|
||||
function DiagnosticsDecorator:highlight_group(node)
|
||||
if self.highlight_range == "none" then
|
||||
return nil
|
||||
end
|
||||
@ -102,4 +102,4 @@ function DecoratorDiagnostics:highlight_group(node)
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorDiagnostics
|
||||
return DiagnosticsDecorator
|
||||
|
||||
@ -12,20 +12,20 @@ local DirectoryNode = require("nvim-tree.node.directory")
|
||||
---@alias GitIconsByXY table<GitXY, GitHighlightedString[]> porcelain status
|
||||
---@alias GitGlyphsByStatus table<GitStatusStrings, string> from opts
|
||||
|
||||
---@class (exact) DecoratorGit: Decorator
|
||||
---@class (exact) GitDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private file_hl_by_xy table<GitXY, string>?
|
||||
---@field private folder_hl_by_xy table<GitXY, string>?
|
||||
---@field private icons_by_status GitIconsByStatus?
|
||||
---@field private icons_by_xy GitIconsByXY?
|
||||
local DecoratorGit = Decorator:extend()
|
||||
local GitDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorGit
|
||||
---@overload fun(args: DecoratorArgs): DecoratorGit
|
||||
---@class GitDecorator
|
||||
---@overload fun(args: DecoratorArgs): GitDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorGit:new(args)
|
||||
function GitDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = self.explorer.opts.git.enable
|
||||
@ -51,7 +51,7 @@ function DecoratorGit:new(args)
|
||||
end
|
||||
|
||||
---@param glyphs GitGlyphsByStatus
|
||||
function DecoratorGit:build_icons_by_status(glyphs)
|
||||
function GitDecorator:build_icons_by_status(glyphs)
|
||||
self.icons_by_status = {}
|
||||
self.icons_by_status.staged = { str = glyphs.staged, hl = { "NvimTreeGitStagedIcon" }, ord = 1 }
|
||||
self.icons_by_status.unstaged = { str = glyphs.unstaged, hl = { "NvimTreeGitDirtyIcon" }, ord = 2 }
|
||||
@ -63,7 +63,7 @@ function DecoratorGit:build_icons_by_status(glyphs)
|
||||
end
|
||||
|
||||
---@param icons GitIconsByXY
|
||||
function DecoratorGit:build_icons_by_xy(icons)
|
||||
function GitDecorator:build_icons_by_xy(icons)
|
||||
self.icons_by_xy = {
|
||||
["M "] = { icons.staged },
|
||||
[" M"] = { icons.unstaged },
|
||||
@ -100,7 +100,7 @@ function DecoratorGit:build_icons_by_xy(icons)
|
||||
}
|
||||
end
|
||||
|
||||
function DecoratorGit:build_file_folder_hl_by_xy()
|
||||
function GitDecorator:build_file_folder_hl_by_xy()
|
||||
self.file_hl_by_xy = {
|
||||
["M "] = "NvimTreeGitFileStagedHL",
|
||||
["C "] = "NvimTreeGitFileStagedHL",
|
||||
@ -143,7 +143,7 @@ end
|
||||
---Git icons: git.enable, renderer.icons.show.git and node has status
|
||||
---@param node Node
|
||||
---@return HighlightedString[]? icons
|
||||
function DecoratorGit:icons(node)
|
||||
function GitDecorator:icons(node)
|
||||
if not self.icons_by_xy then
|
||||
return nil
|
||||
end
|
||||
@ -190,7 +190,7 @@ end
|
||||
---Get the first icon as the sign if appropriate
|
||||
---@param node Node
|
||||
---@return string|nil name
|
||||
function DecoratorGit:sign_name(node)
|
||||
function GitDecorator:sign_name(node)
|
||||
if self.icon_placement ~= "signcolumn" then
|
||||
return
|
||||
end
|
||||
@ -204,7 +204,7 @@ end
|
||||
---Git highlight: git.enable, renderer.highlight_git and node has status
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorGit:highlight_group(node)
|
||||
function GitDecorator:highlight_group(node)
|
||||
if self.highlight_range == "none" then
|
||||
return nil
|
||||
end
|
||||
@ -221,4 +221,4 @@ function DecoratorGit:highlight_group(node)
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorGit
|
||||
return GitDecorator
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorHidden: Decorator
|
||||
---@class (exact) HiddenDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private icon HighlightedString?
|
||||
local DecoratorHidden = Decorator:extend()
|
||||
local HiddenDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorHidden
|
||||
---@overload fun(args: DecoratorArgs): DecoratorHidden
|
||||
---@class HiddenDecorator
|
||||
---@overload fun(args: DecoratorArgs): HiddenDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorHidden:new(args)
|
||||
function HiddenDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -30,7 +30,7 @@ end
|
||||
---Hidden icon: renderer.icons.show.hidden and node starts with `.` (dotfile).
|
||||
---@param node Node
|
||||
---@return HighlightedString[]? icons
|
||||
function DecoratorHidden:icons(node)
|
||||
function HiddenDecorator:icons(node)
|
||||
if node:is_dotfile() then
|
||||
return { self.icon }
|
||||
end
|
||||
@ -39,7 +39,7 @@ end
|
||||
---Hidden highlight: renderer.highlight_hidden and node starts with `.` (dotfile).
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorHidden:highlight_group(node)
|
||||
function HiddenDecorator:highlight_group(node)
|
||||
if self.highlight_range == "none" or not node:is_dotfile() then
|
||||
return nil
|
||||
end
|
||||
@ -51,4 +51,4 @@ function DecoratorHidden:highlight_group(node)
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorHidden
|
||||
return HiddenDecorator
|
||||
|
||||
@ -3,17 +3,17 @@ local buffers = require("nvim-tree.buffers")
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorModified: Decorator
|
||||
---@class (exact) ModifiedDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private icon HighlightedString?
|
||||
local DecoratorModified = Decorator:extend()
|
||||
local ModifiedDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorModified
|
||||
---@overload fun(args: DecoratorArgs): DecoratorModified
|
||||
---@class ModifiedDecorator
|
||||
---@overload fun(args: DecoratorArgs): ModifiedDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorModified:new(args)
|
||||
function ModifiedDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -32,7 +32,7 @@ end
|
||||
---Modified icon: modified.enable, renderer.icons.show.modified and node is modified
|
||||
---@param node Node
|
||||
---@return HighlightedString[]? icons
|
||||
function DecoratorModified:icons(node)
|
||||
function ModifiedDecorator:icons(node)
|
||||
if buffers.is_modified(node) then
|
||||
return { self.icon }
|
||||
end
|
||||
@ -41,7 +41,7 @@ end
|
||||
---Modified highlight: modified.enable, renderer.highlight_modified and node is modified
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorModified:highlight_group(node)
|
||||
function ModifiedDecorator:highlight_group(node)
|
||||
if self.highlight_range == "none" or not buffers.is_modified(node) then
|
||||
return nil
|
||||
end
|
||||
@ -53,4 +53,4 @@ function DecoratorModified:highlight_group(node)
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorModified
|
||||
return ModifiedDecorator
|
||||
|
||||
@ -2,17 +2,17 @@ local buffers = require("nvim-tree.buffers")
|
||||
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---@class (exact) DecoratorOpened: Decorator
|
||||
---@class (exact) OpenDecorator: Decorator
|
||||
---@field private explorer Explorer
|
||||
---@field private icon HighlightedString|nil
|
||||
local DecoratorOpened = Decorator:extend()
|
||||
local OpenDecorator = Decorator:extend()
|
||||
|
||||
---@class DecoratorOpened
|
||||
---@overload fun(args: DecoratorArgs): DecoratorOpened
|
||||
---@class OpenDecorator
|
||||
---@overload fun(args: DecoratorArgs): OpenDecorator
|
||||
|
||||
---@protected
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorOpened:new(args)
|
||||
function OpenDecorator:new(args)
|
||||
self.explorer = args.explorer
|
||||
|
||||
self.enabled = true
|
||||
@ -23,10 +23,10 @@ end
|
||||
---Opened highlight: renderer.highlight_opened_files and node has an open buffer
|
||||
---@param node Node
|
||||
---@return string? highlight_group
|
||||
function DecoratorOpened:highlight_group(node)
|
||||
function OpenDecorator:highlight_group(node)
|
||||
if self.highlight_range ~= "none" and buffers.is_opened(node) then
|
||||
return "NvimTreeOpenedHL"
|
||||
end
|
||||
end
|
||||
|
||||
return DecoratorOpened
|
||||
return OpenDecorator
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
local Decorator = require("nvim-tree.renderer.decorator")
|
||||
|
||||
---Exposed as nvim_tree.api.decorator.DecoratorUser
|
||||
---@class (exact) DecoratorUser: Decorator
|
||||
local DecoratorUser = Decorator:extend()
|
||||
---Exposed as nvim_tree.api.decorator.UserDecorator
|
||||
---@class (exact) UserDecorator: Decorator
|
||||
local UserDecorator = Decorator:extend()
|
||||
|
||||
return DecoratorUser
|
||||
return UserDecorator
|
||||
|
||||
Loading…
Reference in New Issue
Block a user