Skip to content

Commit 09d9caa

Browse files
fix: ensure icon overrides apply after refresh (#573)
* fix: ensure icon overrides apply after refresh * org filetype newly added to nvim --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent 4c3a584 commit 09d9caa

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: colors
2222
name: colors
2323
description: Ensures Light Color Scheme version has been generated.
24-
entry: make colors
24+
entry: make colors-check
2525
language: system
2626
require_serial: true
2727
pass_filenames: false

lua/nvim-web-devicons.lua

+43-37
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local M = {}
1111
-- NOTE: When adding new icons, remember to add an entry to the `filetypes` table, if applicable.
1212
local icons, icons_by_filename, icons_by_file_extension, icons_by_operating_system
1313
local icons_by_desktop_environment, icons_by_window_manager
14+
local user_icons
1415

1516
local filetypes = require "nvim-web-devicons.filetypes"
1617

@@ -197,39 +198,7 @@ local function get_highlight_ctermfg(icon_data)
197198
end
198199
end
199200

200-
local loaded = false
201-
202-
function M.has_loaded()
203-
return loaded
204-
end
205-
206-
local if_nil = vim.F.if_nil
207-
function M.setup(opts)
208-
if loaded then
209-
return
210-
end
211-
212-
loaded = true
213-
214-
local user_icons = opts or {}
215-
216-
if user_icons.default then
217-
global_opts.default = true
218-
end
219-
220-
if user_icons.strict then
221-
global_opts.strict = true
222-
end
223-
224-
global_opts.color_icons = if_nil(user_icons.color_icons, global_opts.color_icons)
225-
226-
if user_icons.variant == "light" or user_icons.variant == "dark" then
227-
global_opts.variant = user_icons.variant
228-
229-
-- Reload the icons after setting variant option
230-
refresh_icons()
231-
end
232-
201+
local function apply_user_icons()
233202
if user_icons.override and user_icons.override.default_icon then
234203
default_icon = user_icons.override.default_icon
235204
end
@@ -283,6 +252,42 @@ function M.setup(opts)
283252
end
284253

285254
icons[1] = default_icon
255+
end
256+
257+
local loaded = false
258+
259+
function M.has_loaded()
260+
return loaded
261+
end
262+
263+
local if_nil = vim.F.if_nil
264+
function M.setup(opts)
265+
if loaded then
266+
return
267+
end
268+
269+
loaded = true
270+
271+
user_icons = opts or {}
272+
273+
if user_icons.default then
274+
global_opts.default = true
275+
end
276+
277+
if user_icons.strict then
278+
global_opts.strict = true
279+
end
280+
281+
global_opts.color_icons = if_nil(user_icons.color_icons, global_opts.color_icons)
282+
283+
if user_icons.variant == "light" or user_icons.variant == "dark" then
284+
global_opts.variant = user_icons.variant
285+
286+
-- Reload the icons after setting variant option
287+
refresh_icons()
288+
end
289+
290+
apply_user_icons()
286291

287292
M.set_up_highlights()
288293

@@ -419,14 +424,14 @@ function M.get_icon_cterm_color_by_filetype(ft, opts)
419424
return M.get_icon_cterm_color(name or "", nil, opts)
420425
end
421426

422-
function M.set_icon(user_icons)
423-
icons = vim.tbl_extend("force", icons, user_icons or {})
424-
global_opts.override = vim.tbl_extend("force", global_opts.override, user_icons or {})
427+
function M.set_icon(user_icons_opts)
428+
icons = vim.tbl_extend("force", icons, user_icons_opts or {})
429+
global_opts.override = vim.tbl_extend("force", global_opts.override, user_icons_opts or {})
425430
if not global_opts.color_icons then
426431
return
427432
end
428433

429-
for _, icon_data in pairs(user_icons) do
434+
for _, icon_data in pairs(user_icons_opts) do
430435
set_up_highlight(icon_data)
431436
end
432437
end
@@ -447,6 +452,7 @@ refresh_icons()
447452

448453
function M.refresh()
449454
refresh_icons()
455+
apply_user_icons()
450456
M.set_up_highlights(true)
451457
end
452458

lua/nvim-web-devicons/filetypes.lua

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ return {
132132
["odin"] = "odin",
133133
["openscad"] = "scad",
134134
["opus"] = "opus",
135+
["org"] = "org",
135136
["otf"] = "otf",
136137
["pck"] = "pck",
137138
["pdf"] = "pdf",

0 commit comments

Comments
 (0)