fix(buffer): keep conceal active in all modes and add %l EOL forge labels

Problem: `concealcursor` was missing `i` and `v`, so concealed text
(task IDs, forge tokens) leaked in insert and visual modes. Forge
labels only rendered for the first span when multiple refs existed.

Solution: set `concealcursor = 'nicv'` to keep conceal in all modes.
Add `%l` EOL format specifier that renders all forge spans with
independent highlights. Update default `eol_format` to include `%l`.
This commit is contained in:
Barrett Ruth 2026-03-15 13:19:32 -04:00
parent 1266eaedd8
commit 9830ab84a1
3 changed files with 33 additions and 18 deletions

View file

@ -901,12 +901,13 @@ Fields: ~
The view to use when the buffer is opened The view to use when the buffer is opened
for the first time in a session. for the first time in a session.
{eol_format} (string, default: '%c %r %d') {eol_format} (string, default: '%c %r %d %l')
Format string for end-of-line virtual text. Format string for end-of-line virtual text.
Specifiers: Specifiers:
`%c` category icon + name (`PendingHeader`) `%c` category icon + name (`PendingHeader`)
`%r` recurrence icon + pattern (`PendingRecur`) `%r` recurrence icon + pattern (`PendingRecur`)
`%d` due icon + date (`PendingDue`/`PendingOverdue`) `%d` due icon + date (`PendingDue`/`PendingOverdue`)
`%l` forge link label (`PendingForge`/`PendingForgeClosed`)
Literal text between specifiers acts as a Literal text between specifiers acts as a
separator. Absent fields and surrounding separator. Absent fields and surrounding
literals are collapsed automatically. `%c` literals are collapsed automatically. `%c`
@ -1572,10 +1573,9 @@ Example: >
< <
On `:w`, the forge reference stays in the description and is also stored in On `:w`, the forge reference stays in the description and is also stored in
the task's `_extra._forge_ref` field. The raw token is visually replaced the task's `_extra._forge_ref` field. The raw token is concealed in the
inline with a formatted label using overlay extmarks (same technique as buffer and a formatted label appears at the end of the line via the `%l`
checkbox icons). Multiple forge references in one line are each overlaid EOL format specifier.
independently.
Format string: ~ Format string: ~
*pending-forge-format* *pending-forge-format*

View file

@ -183,14 +183,10 @@ local function apply_inline_row(bufnr, row, m, icons)
invalidate = true, invalidate = true,
}) })
if m.forge_spans then if m.forge_spans then
local forge = require('pending.forge')
for _, span in ipairs(m.forge_spans) do for _, span in ipairs(m.forge_spans) do
local label_text, hl_group = forge.format_label(span.ref, span.cache)
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, span.col_start, { vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, span.col_start, {
end_col = span.col_end, end_col = span.col_end,
conceal = '', conceal = '',
virt_text = { { label_text, hl_group } },
virt_text_pos = 'inline',
priority = 90, priority = 90,
invalidate = true, invalidate = true,
}) })
@ -215,7 +211,7 @@ end
---@param line string ---@param line string
---@return string? ---@return string?
local function infer_status(line) local function infer_status(line)
local ch = line:match('^/%d+/%- %[(.)%]') or line:match('^%- %[(.)%]') local ch = line:match('^/%d+/%[(.)%]') or line:match('^%[(.)%]')
if not ch then if not ch then
return nil return nil
end end
@ -399,7 +395,7 @@ end
---@param winid integer ---@param winid integer
local function set_win_options(winid) local function set_win_options(winid)
vim.wo[winid].conceallevel = 3 vim.wo[winid].conceallevel = 3
vim.wo[winid].concealcursor = 'nc' vim.wo[winid].concealcursor = 'nicv'
vim.wo[winid].winfixheight = true vim.wo[winid].winfixheight = true
end end
@ -411,7 +407,7 @@ local function setup_syntax(bufnr)
syntax match taskId /^\/\d\+\// conceal syntax match taskId /^\/\d\+\// conceal
syntax match taskHeader /^# .*$/ contains=taskId syntax match taskHeader /^# .*$/ contains=taskId
syntax match taskCheckbox /\[!\]/ contained containedin=taskLine syntax match taskCheckbox /\[!\]/ contained containedin=taskLine
syntax match taskLine /^\/\d\+\/- \[.\] .*$/ contains=taskId,taskCheckbox syntax match taskLine /^\/\d\+\/\[.\] .*$/ contains=taskId,taskCheckbox
]]) ]])
end) end)
end end
@ -429,7 +425,7 @@ function M.open_line(above)
_rendering = true _rendering = true
vim.bo[bufnr].modifiable = true vim.bo[bufnr].modifiable = true
vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '- [ ] ' }) vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '[ ] ' })
_rendering = false _rendering = false
table.insert(_meta, meta_pos, { type = 'task' }) table.insert(_meta, meta_pos, { type = 'task' })
@ -444,7 +440,7 @@ function M.open_line(above)
end end
end end
vim.api.nvim_win_set_cursor(0, { insert_row + 1, 6 }) vim.api.nvim_win_set_cursor(0, { insert_row + 1, 4 })
vim.cmd('startinsert!') vim.cmd('startinsert!')
end end
@ -478,7 +474,7 @@ local function parse_eol_format(fmt)
while pos <= len do while pos <= len do
if fmt:sub(pos, pos) == '%' and pos + 1 <= len then if fmt:sub(pos, pos) == '%' and pos + 1 <= len then
local key = fmt:sub(pos + 1, pos + 1) local key = fmt:sub(pos + 1, pos + 1)
if key == 'c' or key == 'r' or key == 'd' then if key == 'c' or key == 'r' or key == 'd' or key == 'l' then
table.insert(segments, { type = 'specifier', key = key }) table.insert(segments, { type = 'specifier', key = key })
pos = pos + 2 pos = pos + 2
else else
@ -514,8 +510,21 @@ local function build_eol_virt(segments, m, icons)
elseif seg.key == 'd' and m.due then elseif seg.key == 'd' and m.due then
text = icons.due .. ' ' .. m.due text = icons.due .. ' ' .. m.due
hl = due_hl hl = due_hl
elseif seg.key == 'l' and m.forge_spans and #m.forge_spans > 0 then
local forge = require('pending.forge')
local parts = {}
for j, span in ipairs(m.forge_spans) do
local lt, lh = forge.format_label(span.ref, span.cache)
if j > 1 then
table.insert(parts, { text = ' ', hl = 'Normal' })
end end
table.insert(parts, { text = lt, hl = lh })
end
resolved[i] = { multi = parts, present = true }
end
if not resolved[i] then
resolved[i] = text and { text = text, hl = hl, present = true } or { present = false } resolved[i] = text and { text = text, hl = hl, present = true } or { present = false }
end
else else
resolved[i] = { text = seg.text, hl = 'Normal', literal = true } resolved[i] = { text = seg.text, hl = 'Normal', literal = true }
end end
@ -533,7 +542,13 @@ local function build_eol_virt(segments, m, icons)
table.insert(virt_parts, pending_sep) table.insert(virt_parts, pending_sep)
pending_sep = nil pending_sep = nil
end end
if r.multi then
for _, part in ipairs(r.multi) do
table.insert(virt_parts, { part.text, part.hl })
end
else
table.insert(virt_parts, { r.text, r.hl }) table.insert(virt_parts, { r.text, r.hl })
end
else else
pending_sep = nil pending_sep = nil
end end

View file

@ -131,7 +131,7 @@ local defaults = {
max_priority = 3, max_priority = 3,
view = { view = {
default = 'category', default = 'category',
eol_format = '%c %r %d', eol_format = '%c %r %d %l',
category = { category = {
order = {}, order = {},
folding = true, folding = true,