-
-
Notifications
You must be signed in to change notification settings - Fork 622
feat: add renderer.highlight_hidden, renderer.icons.show.hidden and renderer.icons.hidden_placement for dotfile icons/highlights #2840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3b37b51
fd0d2de
59571f6
7d28464
605b361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/luals-out/ | ||
/luals/ | ||
# backup vim files | ||
*~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,11 @@ M.HIGHLIGHT_GROUPS = { | |
{ group = "NvimTreeModifiedFileHL", link = "NvimTreeModifiedIcon" }, | ||
{ group = "NvimTreeModifiedFolderHL", link = "NvimTreeModifiedFileHL" }, | ||
|
||
-- Hidden | ||
{ group = "NvimTreeHiddenIcon", link = "NvimTreeSignColumn" }, | ||
{ group = "NvimTreeHiddenFileHL", link = "NvimTreeFileName" }, | ||
{ group = "NvimTreeHiddenFolderHL", link = "NvimTreeFolderName" }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
-- Opened | ||
{ group = "NvimTreeOpenedHL", link = "Special" }, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,20 @@ function M.is_git_ignored(node) | |
return node and node.git_status ~= nil and node.git_status.file == "!!" | ||
end | ||
|
||
---@param node Node | ||
---@return boolean | ||
function M.is_dotfile(node) | ||
if node == nil then | ||
return false | ||
end | ||
-- Inspect(node) | ||
if node.is_dot or (node.name and (node.name:sub(1, 1) == ".")) or M.is_dotfile(node.parent) then | ||
node.is_dot = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
return true | ||
end | ||
return false | ||
end | ||
|
||
---@param node Node | ||
function M.node_destroy(node) | ||
if not node then | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ 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 DecoratorModified = require "nvim-tree.renderer.decorator.modified" | ||
local DecoratorHidden = require "nvim-tree.renderer.decorator.hidden" | ||
local DecoratorOpened = require "nvim-tree.renderer.decorator.opened" | ||
|
||
local pad = require "nvim-tree.renderer.components.padding" | ||
|
@@ -442,6 +443,7 @@ function Builder.setup(opts) | |
DecoratorDiagnostics:new(opts), | ||
DecoratorBookmarks:new(opts), | ||
DecoratorModified:new(opts), | ||
DecoratorHidden:new(opts), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
DecoratorOpened:new(opts), | ||
DecoratorGit:new(opts), | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||
local is_dotfile = require("nvim-tree.explorer.node").is_dotfile | ||||||
local HL_POSITION = require("nvim-tree.enum").HL_POSITION | ||||||
local ICON_PLACEMENT = require("nvim-tree.enum").ICON_PLACEMENT | ||||||
|
||||||
local Decorator = require "nvim-tree.renderer.decorator" | ||||||
|
||||||
---@class DecoratorHidden: Decorator | ||||||
---@field icon HighlightedString|nil | ||||||
local DecoratorHidden = Decorator:new() | ||||||
|
||||||
---@param opts table | ||||||
---@return DecoratorHidden | ||||||
function DecoratorHidden:new(opts) | ||||||
local o = Decorator.new(self, { | ||||||
enabled = true, | ||||||
hl_pos = HL_POSITION[opts.renderer.highlight_hidden] or HL_POSITION.none, | ||||||
icon_placement = ICON_PLACEMENT[opts.renderer.icons.hidden_placement] or ICON_PLACEMENT.none, | ||||||
}) | ||||||
---@cast o DecoratorHidden | ||||||
|
||||||
if not o.enabled then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
return o | ||||||
end | ||||||
|
||||||
if opts.renderer.icons.show.hidden then | ||||||
o.icon = { | ||||||
str = opts.renderer.icons.glyphs.hidden, | ||||||
hl = { "NvimTreeHiddenIcon" }, | ||||||
} | ||||||
o:define_sign(o.icon) | ||||||
end | ||||||
|
||||||
return o | ||||||
end | ||||||
|
||||||
---Hidden icon: hidden.enable, renderer.icons.show.hidden and node starts with `.` (dotfile). | ||||||
---@param node Node | ||||||
---@return HighlightedString[]|nil icons | ||||||
function DecoratorHidden:calculate_icons(node) | ||||||
if self.enabled and is_dotfile(node) then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can then remove the require. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated in favor of all sugestions. However, I couldn't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right you are; node isn't yet a proper class. Apologies... |
||||||
return { self.icon } | ||||||
end | ||||||
end | ||||||
|
||||||
---Hidden highlight: hidden.enable, renderer.highlight_hidden and node starts with `.` (dotfile). | ||||||
---@param node Node | ||||||
---@return string|nil group | ||||||
function DecoratorHidden:calculate_highlight(node) | ||||||
if not self.enabled or self.hl_pos == HL_POSITION.none or not (is_dotfile(node)) then | ||||||
return nil | ||||||
end | ||||||
|
||||||
if node.nodes then | ||||||
return "NvimTreeHiddenFolderHL" | ||||||
else | ||||||
return "NvimTreeHiddenFileHL" | ||||||
end | ||||||
end | ||||||
|
||||||
return DecoratorHidden |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make help-update
to add the new entries to the indexes:https://github.com/nvim-tree/nvim-tree.lua/actions/runs/9958922100/job/27689198158?pr=2840