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

feat(doom): Add icon_offset to entry menu options. #423

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ config = {
{
icon = '',
icon_hl = 'group',
icon_offset = 0, -- Use for non-standard width glyphs to fix the cursor column position at the menu entry
desc = 'description',
desc_hl = 'group',
key = 'shortcut key in dashboard buffer not keymap !!',
Expand Down
18 changes: 16 additions & 2 deletions lua/dashboard/theme/doom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ local function generate_center(config)
}

local counts = {}
for _, item in pairs(center) do
local icons_offsets = {}
for item_idx, item in pairs(center) do
local count = item.keymap and #item.keymap or 0
local line = (item.icon or '') .. item.desc

Expand Down Expand Up @@ -39,6 +40,10 @@ local function generate_center(config)
line = line .. (' '):rep(#item.keymap)
end

if item.icon_offset then
table.insert(icons_offsets, { item_idx * 2 - 1, item.icon_offset })
end

table.insert(lines, line)
table.insert(lines, '')
table.insert(counts, count)
Expand All @@ -58,6 +63,11 @@ local function generate_center(config)
return
end

local col_offsets = {}
for _, offset in pairs(icons_offsets) do
col_offsets[offset[1] + first_line] = offset[2]
end

local ns = api.nvim_create_namespace('DashboardDoom')
local seed = 0
local pos_map = {}
Expand Down Expand Up @@ -129,7 +139,11 @@ local function generate_center(config)
curline = curline + (before > curline and -1 or 1)
end
before = curline
api.nvim_win_set_cursor(config.winid, { curline, col })
if not col_offsets[curline] then
api.nvim_win_set_cursor(config.winid, { curline, col })
else
api.nvim_win_set_cursor(config.winid, { curline, col + col_offsets[curline] })
end
end,
})
end, 0)
Expand Down
Loading