Skip to content

Commit 60288f4

Browse files
committed
feat(#2415): normalise and add modified groups
1 parent ecca191 commit 60288f4

File tree

6 files changed

+66
-55
lines changed

6 files changed

+66
-55
lines changed

doc/nvim-tree-lua.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,6 @@ Standard: >
22222222
File Text: >
22232223
NvimTreeExecFile Constant
22242224
NvimTreeImageFile PreProc
2225-
NvimTreeModifiedFile Constant
22262225
NvimTreeOpenedFile Constant
22272226
NvimTreeSpecialFile PreProc
22282227
NvimTreeSymlink Statement
@@ -2251,12 +2250,15 @@ Clipboard: >
22512250
NvimTreeCopiedHL SpellRare
22522251
NvimTreeCutHL SpellBad
22532252
<
2254-
Bookmark Icon: >
2253+
Bookmarks: >
22552254
NvimTreeBookmark Constant
2256-
<
2257-
Bookmark Highlight: >
22582255
NvimTreeBookmarkHL SpellLocal
22592256
<
2257+
Modified: >
2258+
NvimTreeModifiedIcon Constant
2259+
NvimTreeModifiedFileHL NvimTreeModifiedIcon
2260+
NvimTreeModifiedFolderHL NvimTreeModifiedIcon
2261+
<
22602262
Picker: >
22612263
NvimTreeWindowPicker guifg=#ededed guibg=#4493c8 gui=bold ctermfg=White ctermbg=Cyan
22622264
<
@@ -2273,7 +2275,7 @@ Git Icon: >
22732275
NvimTreeGitRenamedIcon PreProc
22742276
NvimTreeGitStagedIcon Constant
22752277
<
2276-
Git File Text: >
2278+
Git File File Highlight: >
22772279
NvimTreeGitFileDeletedHL NvimTreeGitDeletedIcon
22782280
NvimTreeGitFileDirtyHL NvimTreeGitDirtyIcon
22792281
NvimTreeGitFileIgnoredHL NvimTreeGitIgnoredIcon
@@ -2282,7 +2284,7 @@ Git File Text: >
22822284
NvimTreeGitFileRenamedHL NvimTreeGitRenamedIcon
22832285
NvimTreeGitFileStagedHL NvimTreeGitStagedIcon
22842286
<
2285-
Git Folder Text: >
2287+
Git Folder Folder Highlight: >
22862288
NvimTreeGitFolderDeletedHL NvimTreeGitFileDeletedHL
22872289
NvimTreeGitFolderDirtyHL NvimTreeGitFileDirtyHL
22882290
NvimTreeGitFolderIgnoredHL NvimTreeGitFileIgnoredHL
@@ -2339,6 +2341,8 @@ Legacy diagnostic HL style may be applied: >
23392341
Legacy highlight group are still obeyed when they are defined and the current
23402342
highlight group is not, hard linking as follows: >
23412343
2344+
NvimTreeModifiedIcon NvimTreeModifiedFile
2345+
23422346
NvimTreeGitDeletedIcon NvimTreeGitDeleted
23432347
NvimTreeGitDirtyIcon NvimTreeGitDirty
23442348
NvimTreeGitIgnoredIcon NvimTreeGitIgnored

lua/nvim-tree/colors.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ local DEFAULT_LINKS = {
3131
-- File Text
3232
NvimTreeExecFile = "Constant",
3333
NvimTreeImageFile = "PreProc",
34-
NvimTreeModifiedFile = "Constant",
3534
NvimTreeOpenedFile = "Constant",
3635
NvimTreeSpecialFile = "PreProc",
3736
NvimTreeSymlink = "Statement",
@@ -65,6 +64,11 @@ local DEFAULT_LINKS = {
6564
-- Bookmark Highlight
6665
NvimTreeBookmarkHL = "SpellLocal",
6766

67+
-- Modified
68+
NvimTreeModifiedIcon = "Constant",
69+
NvimTreeModifiedFileHL = "NvimTreeModifiedIcon",
70+
NvimTreeModifiedFolderHL = "NvimTreeModifiedFileHL",
71+
6872
-- LiveFilter
6973
NvimTreeLiveFilterPrefix = "PreProc",
7074
NvimTreeLiveFilterValue = "ModeMsg",
@@ -78,7 +82,7 @@ local DEFAULT_LINKS = {
7882
NvimTreeGitRenamedIcon = "PreProc",
7983
NvimTreeGitStagedIcon = "Constant",
8084

81-
-- Git File Text
85+
-- Git File Highlight
8286
NvimTreeGitFileDeletedHL = "NvimTreeGitDeletedIcon",
8387
NvimTreeGitFileDirtyHL = "NvimTreeGitDirtyIcon",
8488
NvimTreeGitFileIgnoredHL = "NvimTreeGitIgnoredIcon",
@@ -87,7 +91,7 @@ local DEFAULT_LINKS = {
8791
NvimTreeGitFileRenamedHL = "NvimTreeGitRenamedIcon",
8892
NvimTreeGitFileStagedHL = "NvimTreeGitStagedIcon",
8993

90-
-- Git Folder Text
94+
-- Git Folder Highlight
9195
NvimTreeGitFolderDeletedHL = "NvimTreeGitFileDeletedHL",
9296
NvimTreeGitFolderDirtyHL = "NvimTreeGitFileDirtyHL",
9397
NvimTreeGitFolderIgnoredHL = "NvimTreeGitFileIgnoredHL",
@@ -117,6 +121,8 @@ local DEFAULT_LINKS = {
117121

118122
-- nvim-tree highlight groups to legacy
119123
local LEGACY_LINKS = {
124+
NvimTreeModifiedIcon = "NvimTreeModifiedFile",
125+
120126
NvimTreeGitDeletedIcon = "NvimTreeGitDeleted",
121127
NvimTreeGitDirtyIcon = "NvimTreeGitDirty",
122128
NvimTreeGitIgnoredIcon = "NvimTreeGitIgnored",

lua/nvim-tree/renderer/builder.lua

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ function Builder:configure_opened_file_highlighting(highlight_opened_files)
5959
return self
6060
end
6161

62-
function Builder:configure_modified_highlighting(highlight_modified)
63-
self.highlight_modified = highlight_modified
64-
return self
65-
end
66-
6762
function Builder:configure_icon_padding(padding)
6863
self.icon_padding = padding or " "
6964
return self
@@ -312,18 +307,6 @@ function Builder:_get_highlight_override(node, unloaded_bufnr)
312307
icon_hl = "NvimTreeOpenedFileIcon"
313308
end
314309
end
315-
316-
-- modified file
317-
local modified_highlight = modified.get_highlight(node)
318-
if modified_highlight then
319-
if self.highlight_modified == "all" or self.highlight_modified == "name" then
320-
name_hl = modified_highlight
321-
end
322-
if self.highlight_modified == "all" or self.highlight_modified == "icon" then
323-
icon_hl = modified_highlight
324-
end
325-
end
326-
327310
return icon_hl, name_hl
328311
end
329312

@@ -440,6 +423,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
440423

441424
-- extra highighting
442425
self:_append_highlight(node, git.get_highlight, icon.hl, name.hl)
426+
-- TODO opened
427+
self:_append_highlight(node, modified.get_highlight, icon.hl, name.hl)
443428
self:_append_highlight(node, bookmarks.get_highlight, icon.hl, name.hl)
444429
self:_append_highlight(node, diagnostics.get_highlight, icon.hl, name.hl)
445430
self:_append_highlight(node, copy_paste.get_highlight, icon.hl, name.hl)

lua/nvim-tree/renderer/components/bookmarks.lua

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local marks = require "nvim-tree.marks"
33
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
44

55
local M = {
6-
ICON = {},
6+
icon = nil,
77
hl_pos = HL_POSITION.none,
88
}
99

@@ -28,8 +28,8 @@ end
2828
---@param node table
2929
---@return HighlightedString|nil bookmark icon
3030
function M.get_icon(node)
31-
if M.config.renderer.icons.show.bookmarks and marks.get_mark(node) then
32-
return M.ICON
31+
if M.icon and marks.get_mark(node) then
32+
return M.icon
3333
end
3434
end
3535

@@ -40,12 +40,16 @@ function M.setup(opts)
4040

4141
M.hl_pos = HL_POSITION[opts.renderer.highlight_bookmarks] or HL_POSITION.none
4242

43-
M.ICON = {
44-
str = opts.renderer.icons.glyphs.bookmark,
45-
hl = { "NvimTreeBookmark" },
46-
}
47-
48-
vim.fn.sign_define(M.ICON.hl[1], { text = M.ICON.str, texthl = M.ICON.hl[1] })
43+
if opts.renderer.icons.show.bookmarks then
44+
M.icon = {
45+
str = opts.renderer.icons.glyphs.bookmark,
46+
hl = { "NvimTreeBookmark" },
47+
}
48+
vim.fn.sign_define(M.icon.hl[1], {
49+
text = M.icon.str,
50+
texthl = M.icon.hl[1],
51+
})
52+
end
4953
end
5054

5155
return M

lua/nvim-tree/renderer/components/modified.lua

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,53 @@
11
local modified = require "nvim-tree.modified"
22

3-
local M = {}
3+
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
44

5-
local HIGHLIGHT = "NvimTreeModifiedFile"
5+
local M = {
6+
icon = nil,
7+
hl_pos = HL_POSITION.none,
8+
}
69

7-
---return modified icon if node is modified, otherwise return empty string
10+
---modified icon if modified
811
---@param node table
912
---@return HighlightedString|nil modified icon
1013
function M.get_icon(node)
11-
if not modified.is_modified(node) or not M.show_icon then
12-
return nil
14+
if M.icon and modified.is_modified(node) then
15+
return M.icon
1316
end
14-
15-
return { str = M.icon, hl = { HIGHLIGHT } }
16-
end
17-
18-
function M.setup_signs()
19-
vim.fn.sign_define(HIGHLIGHT, { text = M.icon, texthl = HIGHLIGHT })
2017
end
2118

19+
---Diagnostics highlight group and position when highlight_diagnostics.
2220
---@param node table
23-
---@return string|nil
21+
---@return HL_POSITION position none when no status
22+
---@return string|nil group only when status
2423
function M.get_highlight(node)
25-
if not modified.is_modified(node) then
26-
return nil
24+
if M.hl_pos == HL_POSITION.none or not modified.is_modified(node) then
25+
return HL_POSITION.none, nil
2726
end
2827

29-
return HIGHLIGHT
28+
if node.nodes then
29+
return M.hl_pos, "NvimTreeModifiedFolderHL"
30+
else
31+
return M.hl_pos, "NvimTreeModifiedFileHL"
32+
end
3033
end
3134

3235
function M.setup(opts)
33-
M.icon = opts.renderer.icons.glyphs.modified
34-
M.show_icon = opts.renderer.icons.show.modified
36+
if not opts.modified.enable then
37+
return
38+
end
3539

36-
if opts.renderer.icons.modified_placement == "signcolumn" then
37-
M.setup_signs()
40+
M.hl_pos = HL_POSITION[opts.renderer.highlight_modified] or HL_POSITION.none
41+
42+
if opts.renderer.icons.show.modified then
43+
M.icon = {
44+
str = opts.renderer.icons.glyphs.modified,
45+
hl = { "NvimTreeModifiedIcon" },
46+
}
47+
vim.fn.sign_define(M.icon.hl[1], {
48+
text = M.icon.str,
49+
texthl = M.icon.hl[1],
50+
})
3851
end
3952
end
4053

lua/nvim-tree/renderer/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ function M.draw(unloaded_bufnr)
7272
:configure_special_files(M.config.special_files)
7373
:configure_picture_map(picture_map)
7474
:configure_opened_file_highlighting(M.config.highlight_opened_files)
75-
:configure_modified_highlighting(M.config.highlight_modified)
7675
:configure_icon_padding(M.config.icons.padding)
7776
:configure_git_icons_placement(M.config.icons.git_placement)
7877
:configure_diagnostics_icon_placement(M.config.icons.diagnostics_placement)

0 commit comments

Comments
 (0)