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
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.
Specifiers:
`%c` category icon + name (`PendingHeader`)
`%r` recurrence icon + pattern (`PendingRecur`)
`%d` due icon + date (`PendingDue`/`PendingOverdue`)
`%l` forge link label (`PendingForge`/`PendingForgeClosed`)
Literal text between specifiers acts as a
separator. Absent fields and surrounding
literals are collapsed automatically. `%c`
@ -1572,10 +1573,9 @@ Example: >
<
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
inline with a formatted label using overlay extmarks (same technique as
checkbox icons). Multiple forge references in one line are each overlaid
independently.
the task's `_extra._forge_ref` field. The raw token is concealed in the
buffer and a formatted label appears at the end of the line via the `%l`
EOL format specifier.
Format string: ~
*pending-forge-format*

View file

@ -183,14 +183,10 @@ local function apply_inline_row(bufnr, row, m, icons)
invalidate = true,
})
if m.forge_spans then
local forge = require('pending.forge')
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, {
end_col = span.col_end,
conceal = '',
virt_text = { { label_text, hl_group } },
virt_text_pos = 'inline',
priority = 90,
invalidate = true,
})
@ -215,7 +211,7 @@ end
---@param line string
---@return string?
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
return nil
end
@ -399,7 +395,7 @@ end
---@param winid integer
local function set_win_options(winid)
vim.wo[winid].conceallevel = 3
vim.wo[winid].concealcursor = 'nc'
vim.wo[winid].concealcursor = 'nicv'
vim.wo[winid].winfixheight = true
end
@ -411,7 +407,7 @@ local function setup_syntax(bufnr)
syntax match taskId /^\/\d\+\// conceal
syntax match taskHeader /^# .*$/ contains=taskId
syntax match taskCheckbox /\[!\]/ contained containedin=taskLine
syntax match taskLine /^\/\d\+\/- \[.\] .*$/ contains=taskId,taskCheckbox
syntax match taskLine /^\/\d\+\/\[.\] .*$/ contains=taskId,taskCheckbox
]])
end)
end
@ -429,7 +425,7 @@ function M.open_line(above)
_rendering = 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
table.insert(_meta, meta_pos, { type = 'task' })
@ -444,7 +440,7 @@ function M.open_line(above)
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!')
end
@ -478,7 +474,7 @@ local function parse_eol_format(fmt)
while pos <= len do
if fmt:sub(pos, pos) == '%' and pos + 1 <= len then
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 })
pos = pos + 2
else
@ -514,8 +510,21 @@ local function build_eol_virt(segments, m, icons)
elseif seg.key == 'd' and m.due then
text = icons.due .. ' ' .. m.due
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
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 }
end
else
resolved[i] = { text = seg.text, hl = 'Normal', literal = true }
end
@ -533,7 +542,13 @@ local function build_eol_virt(segments, m, icons)
table.insert(virt_parts, pending_sep)
pending_sep = nil
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 })
end
else
pending_sep = nil
end

View file

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