Skip to content

fix: ensure icon overrides apply after refresh #573

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: colors
name: colors
description: Ensures Light Color Scheme version has been generated.
entry: make colors
entry: make colors-check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

language: system
require_serial: true
pass_filenames: false
Expand Down
80 changes: 43 additions & 37 deletions lua/nvim-web-devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local M = {}
-- NOTE: When adding new icons, remember to add an entry to the `filetypes` table, if applicable.
local icons, icons_by_filename, icons_by_file_extension, icons_by_operating_system
local icons_by_desktop_environment, icons_by_window_manager
local user_icons

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

Expand Down Expand Up @@ -197,39 +198,7 @@ local function get_highlight_ctermfg(icon_data)
end
end

local loaded = false

function M.has_loaded()
return loaded
end

local if_nil = vim.F.if_nil
function M.setup(opts)
if loaded then
return
end

loaded = true

local user_icons = opts or {}

if user_icons.default then
global_opts.default = true
end

if user_icons.strict then
global_opts.strict = true
end

global_opts.color_icons = if_nil(user_icons.color_icons, global_opts.color_icons)

if user_icons.variant == "light" or user_icons.variant == "dark" then
global_opts.variant = user_icons.variant

-- Reload the icons after setting variant option
refresh_icons()
end

local function apply_user_icons()
if user_icons.override and user_icons.override.default_icon then
default_icon = user_icons.override.default_icon
end
Expand Down Expand Up @@ -283,6 +252,42 @@ function M.setup(opts)
end

icons[1] = default_icon
end

local loaded = false

function M.has_loaded()
return loaded
end

local if_nil = vim.F.if_nil
function M.setup(opts)
if loaded then
return
end

loaded = true

user_icons = opts or {}

if user_icons.default then
global_opts.default = true
end

if user_icons.strict then
global_opts.strict = true
end

global_opts.color_icons = if_nil(user_icons.color_icons, global_opts.color_icons)

if user_icons.variant == "light" or user_icons.variant == "dark" then
global_opts.variant = user_icons.variant

-- Reload the icons after setting variant option
refresh_icons()
end

apply_user_icons()

M.set_up_highlights()

Expand Down Expand Up @@ -419,14 +424,14 @@ function M.get_icon_cterm_color_by_filetype(ft, opts)
return M.get_icon_cterm_color(name or "", nil, opts)
end

function M.set_icon(user_icons)
icons = vim.tbl_extend("force", icons, user_icons or {})
global_opts.override = vim.tbl_extend("force", global_opts.override, user_icons or {})
function M.set_icon(user_icons_opts)
icons = vim.tbl_extend("force", icons, user_icons_opts or {})
global_opts.override = vim.tbl_extend("force", global_opts.override, user_icons_opts or {})
if not global_opts.color_icons then
return
end

for _, icon_data in pairs(user_icons) do
for _, icon_data in pairs(user_icons_opts) do
set_up_highlight(icon_data)
end
end
Expand All @@ -447,6 +452,7 @@ refresh_icons()

function M.refresh()
refresh_icons()
apply_user_icons()
M.set_up_highlights(true)
end

Expand Down
1 change: 1 addition & 0 deletions lua/nvim-web-devicons/filetypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ return {
["odin"] = "odin",
["openscad"] = "scad",
["opus"] = "opus",
["org"] = "org",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated nvim upstream addition. Not worth its own PR.

["otf"] = "otf",
["pck"] = "pck",
["pdf"] = "pdf",
Expand Down
Loading