feat(buffer): render icon overlays from config.icons
Problem: status characters ([ ], [x], [!]) and metadata prefixes are hardcoded literals with no user customization. Solution: read config.icons in apply_extmarks and apply overlay extmarks for checkboxes/headers, replace hardcoded recur ↺ with icons.recur, and prefix due/category virt_text with configurable icon characters.
This commit is contained in:
parent
a4a470ce5a
commit
e867078cbd
1 changed files with 25 additions and 3 deletions
|
|
@ -143,6 +143,7 @@ end
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param line_meta pending.LineMeta[]
|
---@param line_meta pending.LineMeta[]
|
||||||
local function apply_extmarks(bufnr, line_meta)
|
local function apply_extmarks(bufnr, line_meta)
|
||||||
|
local icons = config.get().icons
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, task_ns, 0, -1)
|
vim.api.nvim_buf_clear_namespace(bufnr, task_ns, 0, -1)
|
||||||
for i, m in ipairs(line_meta) do
|
for i, m in ipairs(line_meta) do
|
||||||
local row = i - 1
|
local row = i - 1
|
||||||
|
|
@ -156,13 +157,13 @@ local function apply_extmarks(bufnr, line_meta)
|
||||||
local due_hl = m.overdue and 'PendingOverdue' or 'PendingDue'
|
local due_hl = m.overdue and 'PendingOverdue' or 'PendingDue'
|
||||||
local virt_parts = {}
|
local virt_parts = {}
|
||||||
if m.show_category and m.category then
|
if m.show_category and m.category then
|
||||||
table.insert(virt_parts, { m.category, 'PendingHeader' })
|
table.insert(virt_parts, { icons.category .. ' ' .. m.category, 'PendingHeader' })
|
||||||
end
|
end
|
||||||
if m.recur then
|
if m.recur then
|
||||||
table.insert(virt_parts, { '\u{21bb} ' .. m.recur, 'PendingRecur' })
|
table.insert(virt_parts, { icons.recur .. ' ' .. m.recur, 'PendingRecur' })
|
||||||
end
|
end
|
||||||
if m.due then
|
if m.due then
|
||||||
table.insert(virt_parts, { m.due, due_hl })
|
table.insert(virt_parts, { icons.due .. ' ' .. m.due, due_hl })
|
||||||
end
|
end
|
||||||
if m.file then
|
if m.file then
|
||||||
local display = m.file:match('([^/]+:%d+)$') or m.file
|
local display = m.file:match('([^/]+:%d+)$') or m.file
|
||||||
|
|
@ -185,12 +186,33 @@ local function apply_extmarks(bufnr, line_meta)
|
||||||
hl_group = 'PendingDone',
|
hl_group = 'PendingDone',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
|
||||||
|
local bracket_col = (line:find('%[') or 1) - 1
|
||||||
|
local icon, icon_hl
|
||||||
|
if m.status == 'done' then
|
||||||
|
icon, icon_hl = icons.done, 'PendingDone'
|
||||||
|
elseif m.priority and m.priority > 0 then
|
||||||
|
icon, icon_hl = icons.priority, 'PendingPriority'
|
||||||
|
else
|
||||||
|
icon, icon_hl = icons.pending, 'Normal'
|
||||||
|
end
|
||||||
|
local icon_padded = icon .. ' '
|
||||||
|
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, bracket_col, {
|
||||||
|
virt_text = { { icon_padded, icon_hl } },
|
||||||
|
virt_text_pos = 'overlay',
|
||||||
|
priority = 100,
|
||||||
|
})
|
||||||
elseif m.type == 'header' then
|
elseif m.type == 'header' then
|
||||||
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
|
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
|
||||||
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, 0, {
|
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, 0, {
|
||||||
end_col = #line,
|
end_col = #line,
|
||||||
hl_group = 'PendingHeader',
|
hl_group = 'PendingHeader',
|
||||||
})
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, 0, {
|
||||||
|
virt_text = { { icons.header .. ' ', 'PendingHeader' } },
|
||||||
|
virt_text_pos = 'overlay',
|
||||||
|
priority = 100,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue