@@ -2929,77 +2929,107 @@ Decorators may:
2929
2929
- Set highlight group for the name or icons
2930
2930
- Override node icon
2931
2931
2932
- Specify decorators and their precedence via | nvim-tree.renderer.decorators |
2933
- e.g. defaults with a user decorator class being overridden only by Cut: >lua
2934
- {
2935
- "Git",
2936
- "Open",
2937
- "Hidden",
2938
- "Modified",
2939
- "Bookmark",
2940
- "Diagnostics",
2941
- "Copied",
2942
- MyDecorator,
2943
- "Cut",
2944
- }
2932
+ Create a `nvim_tree.api.decorator.UserDecorator` class and register it with
2933
+ precedence via | nvim-tree.renderer.decorators |
2934
+
2935
+ See | nvim-tree-decorator-example |
2936
+
2937
+ See `nvim- tree/_meta/ api_decorator.lua ` for full class documentation.
2945
2938
2946
- See `nvim- tree/_meta/ api_decorator.lua ` for full
2947
- `nvim_tree.api.decorator.UserDecorator` class documentation.
2948
- <
2949
2939
==============================================================================
2950
2940
11.1. DECORATOR EXAMPLE *nvim-tree-decorator-example*
2941
+
2942
+ A decorator class for nodes named "example", overridind all builtin decorators
2943
+ except for Cut.
2944
+
2945
+ - Highlights node name with `IncSearch `
2946
+ - Creates two icons `" 1" ` and `" 2" ` placed after the node name, highlighted with
2947
+ `DiffAdd ` and `DiffText `
2948
+ - Replaces the node icon with `" N" ` , highlighted with `Error `
2949
+
2950
+ Create a class file `~/.config/nvim/lua/my-decorator.lua `
2951
+
2952
+ Require and register it during | nvim-tree-setup | :
2953
+ >lua
2954
+ local MyDecorator = require("my-decorator")
2955
+
2956
+ require("nvim-tree").setup({
2957
+ renderer = {
2958
+ decorators = {
2959
+ "Git",
2960
+ "Open",
2961
+ "Hidden",
2962
+ "Modified",
2963
+ "Bookmark",
2964
+ "Diagnostics",
2965
+ "Copied",
2966
+ MyDecorator,
2967
+ "Cut",
2968
+ },
2969
+ },
2970
+ })
2971
+ <
2972
+ Contents of `my- decorator.lua ` :
2951
2973
>lua
2952
- ---Create your decorator class
2953
2974
---@class (exact) MyDecorator: nvim_tree.api.decorator.UserDecorator
2954
- ---@field private my_icon nvim_tree.api.HighlightedString
2975
+ ---@field private my_icon1 nvim_tree.api.HighlightedString
2976
+ ---@field private my_icon2 nvim_tree.api.HighlightedString
2977
+ ---@field private my_icon_node nvim_tree.api.HighlightedString
2978
+ ---@field private my_highlight_group string
2955
2979
local MyDecorator = require("nvim-tree.api").decorator.UserDecorator:extend()
2956
2980
2957
2981
---Mandatory constructor :new() will be called once per tree render, with no arguments.
2958
2982
function MyDecorator:new()
2959
- self.enabled = true
2960
- self.highlight_range = "all "
2961
- self.icon_placement = "signcolumn "
2983
+ self.enabled = true
2984
+ self.highlight_range = "name "
2985
+ self.icon_placement = "after "
2962
2986
2963
- -- create your icon once, for convenience
2964
- self.my_icon = { str = "I", hl = { "MyIcon" } }
2987
+ -- create your icons and highlights once, applied to every node
2988
+ self.my_icon1 = { str = "1", hl = { "DiffAdd" } }
2989
+ self.my_icon2 = { str = "2", hl = { "DiffText" } }
2990
+ self.my_icon_node = { str = "N", hl = { "Error" } }
2991
+ self.my_highlight_group = "IncSearch"
2965
2992
2966
- -- Define the icon sign only once
2993
+ -- Define the icon signs only once
2967
2994
-- Only needed if you are using icon_placement = "signcolumn"
2968
- self:define_sign(self.my_icon)
2995
+ -- self:define_sign(self.my_icon1)
2996
+ -- self:define_sign(self.my_icon2)
2969
2997
end
2970
2998
2971
2999
---Override node icon
2972
3000
---@param node nvim_tree.api.Node
2973
3001
---@return nvim_tree.api.HighlightedString? icon_node
2974
3002
function MyDecorator:icon_node(node)
2975
3003
if node.name == "example" then
2976
- return self.my_icon
3004
+ return self.my_icon_node
2977
3005
else
2978
3006
return nil
2979
3007
end
2980
3008
end
2981
3009
2982
- ---Return one icon for DecoratorIconPlacement
3010
+ ---Return two icons for DecoratorIconPlacement "after"
2983
3011
---@param node nvim_tree.api.Node
2984
3012
---@return nvim_tree.api.HighlightedString[]? icons
2985
3013
function MyDecorator:icons(node)
2986
3014
if node.name == "example" then
2987
- return { self.my_icon }
3015
+ return { self.my_icon1, self.my_icon2, }
2988
3016
else
2989
3017
return nil
2990
3018
end
2991
3019
end
2992
3020
2993
- ---Exactly one highlight group for DecoratorHighlightRange
3021
+ ---Exactly one highlight group for DecoratorHighlightRange "name"
2994
3022
---@param node nvim_tree.api.Node
2995
3023
---@return string? highlight_group
2996
3024
function MyDecorator:highlight_group(node)
2997
3025
if node.name == "example" then
2998
- return "MyHighlight"
3026
+ return self.my_highlight_group
2999
3027
else
3000
3028
return nil
3001
3029
end
3002
3030
end
3031
+
3032
+ return MyDecorator
3003
3033
<
3004
3034
==============================================================================
3005
3035
12. OS SPECIFIC RESTRICTIONS *nvim-tree-os-specific*
0 commit comments