@@ -9,12 +9,15 @@ local core = require "nvim-tree.core"
9
9
10
10
local api = vim .api
11
11
12
+ local M = {}
13
+
12
14
local lines = {}
13
15
local hl = {}
14
16
local index = 0
15
17
local namespace_id = api .nvim_create_namespace " NvimTreeHighlights"
16
18
17
19
local icon_state = _icons .get_config ()
20
+ local web_devicons = icon_state .has_devicons and require " nvim-web-devicons" or nil
18
21
19
22
local should_hl_opened_files = (vim .g .nvim_tree_highlight_opened_files or 0 ) ~= 0
20
23
63
66
local get_file_icon = function ()
64
67
return " "
65
68
end
66
- if icon_state .show_file_icon then
67
- if icon_state .has_devicons then
68
- local web_devicons = require " nvim-web-devicons"
69
69
70
- get_file_icon = function (fname , extension , line , depth )
71
- local icon , hl_group = web_devicons .get_icon (fname , extension )
70
+ local get_file_icon_default = function (_ , _ , line , depth )
71
+ local hl_group = " NvimTreeFileIcon"
72
+ local icon = icon_state .icons .default
73
+ if # icon > 0 then
74
+ table.insert (hl , { hl_group , line , depth , depth + # icon + 1 })
75
+ end
76
+ return # icon > 0 and icon .. icon_padding or " "
77
+ end
72
78
73
- if icon and hl_group ~= " DevIconDefault" then
74
- if hl_group then
75
- table.insert (hl , { hl_group , line , depth , depth + # icon + 1 })
76
- end
77
- return icon .. icon_padding
78
- elseif string.match (extension , " %.(.*)" ) then
79
- -- If there are more extensions to the file, try to grab the icon for them recursively
80
- return get_file_icon (fname , string.match (extension , " %.(.*)" ), line , depth )
81
- else
82
- return # icon_state .icons .default > 0 and icon_state .icons .default .. icon_padding or " "
83
- end
79
+ local get_file_icon_webdev = function (fname , extension , line , depth )
80
+ local icon , hl_group = web_devicons .get_icon (fname , extension )
81
+ if not M .config .icons .webdev_colors then
82
+ hl_group = " NvimTreeFileIcon"
83
+ end
84
+ if icon and hl_group ~= " DevIconDefault" then
85
+ if hl_group then
86
+ table.insert (hl , { hl_group , line , depth , depth + # icon + 1 })
84
87
end
88
+ return icon .. icon_padding
89
+ elseif string.match (extension , " %.(.*)" ) then
90
+ -- If there are more extensions to the file, try to grab the icon for them recursively
91
+ return get_file_icon (fname , string.match (extension , " %.(.*)" ), line , depth )
85
92
else
86
- get_file_icon = function (_ , _ , line , depth )
87
- local hl_group = " NvimTreeFileIcon"
88
- local icon = icon_state .icons .default
89
- if # icon > 0 then
90
- table.insert (hl , { hl_group , line , depth , depth + # icon + 1 })
91
- end
92
- return # icon > 0 and icon .. icon_padding or " "
93
- end
93
+ return get_file_icon_default (fname , extension , line , depth )
94
+ end
95
+ end
96
+
97
+ if icon_state .show_file_icon then
98
+ if web_devicons then
99
+ get_file_icon = get_file_icon_webdev
100
+ else
101
+ get_file_icon = get_file_icon_default
94
102
end
95
103
end
96
104
@@ -224,8 +232,6 @@ local function update_draw_data(tree, depth, markers)
224
232
end
225
233
end
226
234
227
- local M = {}
228
-
229
235
local function compute_header ()
230
236
if view .is_root_folder_visible (core .get_cwd ()) then
231
237
local root_folder_modifier = vim .g .nvim_tree_root_folder_modifier or " :~"
292
298
function M .setup (opts )
293
299
M .config = {
294
300
indent_markers = opts .renderer .indent_markers ,
301
+ icons = opts .renderer .icons ,
295
302
}
296
303
297
304
require (" nvim-tree.renderer.padding" ).setup (opts )
0 commit comments