-
Notifications
You must be signed in to change notification settings - Fork 96
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
feature: Add support for doublewidth Nerd Font icons #282
Comments
I don't really understand any of this. |
To make doublewidth Nerd Font icons work in Neovim we should mark their codepoints as doublewidth: -- Fix icon width for Nerd Fonts v3.2.1.
vim.fn.setcellwidths {
{ 0x23fb, 0x23fe, 2 }, -- IEC Power Symbols
{ 0x2665, 0x2665, 2 }, -- Octicons
{ 0x2b58, 0x2b58, 2 }, -- IEC Power Symbols
{ 0xe000, 0xe00a, 2 }, -- Pomicons
{ 0xe0b8, 0xe0c8, 2 }, -- Powerline Extra
{ 0xe0ca, 0xe0ca, 2 }, -- Powerline Extra
{ 0xe0cc, 0xe0d7, 2 }, -- Powerline Extra
{ 0xe200, 0xe2a9, 2 }, -- Font Awesome Extension
{ 0xe300, 0xe3e3, 2 }, -- Weather Icons
{ 0xe5fa, 0xe6b5, 2 }, -- Seti-UI + Custom
{ 0xe700, 0xe7c5, 2 }, -- Devicons
{ 0xea60, 0xec1e, 2 }, -- Codicons
{ 0xed00, 0xefce, 2 }, -- Font Awesome
{ 0xf000, 0xf2ff, 2 }, -- Font Awesome
{ 0xf300, 0xf375, 2 }, -- Font Logos
{ 0xf400, 0xf533, 2 }, -- Octicons
{ 0xf0001, 0xf1af0, 2 }, -- Material Design
} With this setup todo-comments (using it default config) show error on loading plugin:
This happens because you define I propose to add a check for actual icon width before defining keywords and add/remove that extra space after an icons depending on check result. |
Here is example implementation: local function fix_sign_width(keyword)
local code = vim.fn.char2nr(keyword.icon, true)
for _, value in ipairs(vim.fn.getcellwidths()) do
if value[1] <= code and code <= value[2] and value[3] > 1 then
return
end
end
keyword.icon = keyword.icon .. ' '
end
---@param opts TodoOptions
local function fix_icons(opts)
for _, keyword in pairs(opts.keywords) do
fix_sign_width(keyword)
end
end
--- Example:
-- Fix icon width for Nerd Fonts v3.2.1.
vim.fn.setcellwidths {
{ 0x23fb, 0x23fe, 2 }, -- IEC Power Symbols
{ 0x2665, 0x2665, 2 }, -- Octicons
{ 0x2b58, 0x2b58, 2 }, -- IEC Power Symbols
{ 0xe000, 0xe00a, 2 }, -- Pomicons
{ 0xe0b8, 0xe0c8, 2 }, -- Powerline Extra
{ 0xe0ca, 0xe0ca, 2 }, -- Powerline Extra
{ 0xe0cc, 0xe0d7, 2 }, -- Powerline Extra
{ 0xe200, 0xe2a9, 2 }, -- Font Awesome Extension
{ 0xe300, 0xe3e3, 2 }, -- Weather Icons
{ 0xe5fa, 0xe6b5, 2 }, -- Seti-UI + Custom
{ 0xe700, 0xe7c5, 2 }, -- Devicons
{ 0xea60, 0xec1e, 2 }, -- Codicons
{ 0xed00, 0xefce, 2 }, -- Font Awesome
{ 0xf000, 0xf2ff, 2 }, -- Font Awesome
{ 0xf300, 0xf375, 2 }, -- Font Logos
{ 0xf400, 0xf533, 2 }, -- Octicons
{ 0xf0001, 0xf1af0, 2 }, -- Material Design
}
---@type TodoOptions
local opts = {
keywords = {
FIX = { icon = '' },
TODO = { icon = '' },
HACK = { icon = '' },
WARN = { icon = '' },
PERF = { icon = '' },
NOTE = { icon = '' },
TEST = { icon = '' },
},
}
fix_icons(opts)
vim.print(opts) |
To repro just add that |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
bump |
Related: neovim/neovim#30014 |
After updating to neovim/neovim@5f95f12,
My config: return {
"folke/todo-comments.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
event = { "BufReadPost", "BufNewFile" },
opts = {
highlight = {
comments_only = false,
},
keywords = {
BUG = { icon = "🐛", color = "error", alt = { "BROKEN", "FIXME", "ISSUE" } },
HACK = { icon = "🔥", color = "warning" },
IDEA = { icon = "💡", color = "test" },
NOTE = { icon = "ℹ️", color = "hint", alt = { "INFO" } },
TEST = { icon = "🧪", color = "test", alt = { "EXPERIMENT", "TESTING" } },
TODO = { icon = "✅", color = "info" },
WARN = { icon = "⚠️", color = "warning", alt = { "WARNING", "XXX" } },
},
},
} Edit: the error is gone now after updating to newer Neovim commits. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
bump |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
bump |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
bump |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Did you check the docs?
Is your feature request related to a problem? Please describe.
Please read neovim/neovim#29496 - it describes patch for Neovim which marks Nerd Font icons doublewidth and this result in breaking your plugin (described in details in neovim/neovim#29496 (comment)).
Describe the solution you'd like
Not sure is mentioned in linked comment fix based on 'ambiwidth' vim option will works, but please consider some solution to the issue.
Describe alternatives you've considered
Manual copy&paste of default icons setup into own custom config and removing extra spaces after icons works. But it's not really convenient for new users who don't want to customize used icons.
Additional context
Sorry, I havn't read all the todo-comments.nvim docs - it's not relevant to the issue, but I had to check the box to submit.
The text was updated successfully, but these errors were encountered: