Skip to content
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

fix(#449): :NvimWebDeviconsHiTest shows default icon, "DevIcon" highlight group prefix, tag first #451

Merged
merged 2 commits into from
Apr 28, 2024
Merged
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
16 changes: 8 additions & 8 deletions lua/nvim-web-devicons/hi-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ end
---Write the line with highlighting
---@param bufnr number buffer number
---@param max_tag_len number longest tag length
---@param max_name_len number longest name length
---@param max_group_len number longest group length
---@param l number line number
---@return number l incremented
function IconDisplay:render(bufnr, max_tag_len, max_name_len, l)
local fmt = string.format("%%s %%-%d.%ds %%-%d.%ds %%s", max_name_len, max_name_len, max_tag_len, max_tag_len)
local text = string.format(fmt, self.icon, self.name, self.tag, self.def)
function IconDisplay:render(bufnr, max_tag_len, max_group_len, l)
local fmt = string.format("%%s %%-%d.%ds %%-%d.%ds %%s", max_tag_len, max_tag_len, max_group_len, max_group_len)
local text = string.format(fmt, self.icon, self.tag, self.group, self.def)

vim.api.nvim_buf_set_lines(bufnr, l, -1, true, { text })
vim.api.nvim_buf_add_highlight(bufnr, -1, self.group, l, 0, -1)
Expand All @@ -66,7 +66,7 @@ end
---@return number l incremented
local function render_icons(bufnr, l, icons, header)
local max_tag_len = 0
local max_name_len = 0
local max_group_len = 0

local displays = {}
---@cast displays IconDisplay[]
Expand All @@ -77,7 +77,7 @@ local function render_icons(bufnr, l, icons, header)
if display then
table.insert(displays, display)
max_tag_len = math.max(max_tag_len, #display.tag)
max_name_len = math.max(max_name_len, #display.name)
max_group_len = math.max(max_group_len, #display.group)
end
end

Expand All @@ -89,7 +89,7 @@ local function render_icons(bufnr, l, icons, header)
l = render_line(bufnr, l, header)
l = render_line(bufnr, l, header:gsub(".", "-"))
for _, display in ipairs(displays) do
l = display:render(bufnr, max_tag_len, max_name_len, l)
l = display:render(bufnr, max_tag_len, max_group_len, l)
end
l = render_line(bufnr, l, "")

Expand Down Expand Up @@ -120,7 +120,7 @@ return function(

-- render and highlight each section
local l = 0
l = render_icons(bufnr, l, { default_icon }, "Default")
l = render_icons(bufnr, l, { [""] = default_icon }, "Default")
if global_override and next(global_override) then
l = render_icons(bufnr, l, global_override, "Overrides")
end
Expand Down
Loading