typechecked optargs constructors for decorators
This commit is contained in:
@@ -7,36 +7,33 @@ local Decorator = require("nvim-tree.renderer.decorator")
|
||||
local DirectoryNode = require("nvim-tree.node.directory")
|
||||
|
||||
---@class (exact) DecoratorModified: Decorator
|
||||
---@field icon HighlightedString|nil
|
||||
local DecoratorModified = Decorator:new()
|
||||
---@field icon HighlightedString?
|
||||
local DecoratorModified = Decorator:extend()
|
||||
|
||||
---Static factory method
|
||||
---@param opts table
|
||||
---@param explorer Explorer
|
||||
---@return DecoratorModified
|
||||
function DecoratorModified:create(opts, explorer)
|
||||
---@type DecoratorModified
|
||||
local o = {
|
||||
explorer = explorer,
|
||||
enabled = opts.modified.enable,
|
||||
hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
|
||||
}
|
||||
o = self:new(o)
|
||||
---@class DecoratorModified
|
||||
---@overload fun(explorer: DecoratorArgs): DecoratorModified
|
||||
|
||||
if not o.enabled then
|
||||
return o
|
||||
---@private
|
||||
---@param args DecoratorArgs
|
||||
function DecoratorModified:new(args)
|
||||
Decorator.new(self, {
|
||||
explorer = args.explorer,
|
||||
enabled = true,
|
||||
hl_pos = HL_POSITION[args.explorer.opts.renderer.highlight_modified] or HL_POSITION.none,
|
||||
icon_placement = ICON_PLACEMENT[args.explorer.opts.renderer.icons.modified_placement] or ICON_PLACEMENT.none,
|
||||
})
|
||||
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
|
||||
if opts.renderer.icons.show.modified then
|
||||
o.icon = {
|
||||
str = opts.renderer.icons.glyphs.modified,
|
||||
if self.explorer.opts.renderer.icons.show.modified then
|
||||
self.icon = {
|
||||
str = self.explorer.opts.renderer.icons.glyphs.modified,
|
||||
hl = { "NvimTreeModifiedIcon" },
|
||||
}
|
||||
o:define_sign(o.icon)
|
||||
self:define_sign(self.icon)
|
||||
end
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Modified icon: modified.enable, renderer.icons.show.modified and node is modified
|
||||
|
||||
Reference in New Issue
Block a user