refactor(buffer): split extmark namespace into ns_eol and ns_inline

Problem: all extmarks shared a single `pending` namespace, making it
impossible to selectively clear position-sensitive extmarks (overlays,
highlights) while preserving stable EOL virtual text (due dates,
recurrence).

Solution: introduce `ns_eol` for end-of-line virtual text and
`ns_inline` for overlays and highlights. `clear_marks()` and
`apply_extmarks()` operate on both namespaces independently.
This commit is contained in:
Barrett Ruth 2026-03-08 14:08:15 -04:00
parent d06731a7fd
commit a12e5b5763

View file

@ -12,7 +12,8 @@ local _store = nil
local task_bufnr = nil
---@type integer?
local task_winid = nil
local task_ns = vim.api.nvim_create_namespace('pending')
local ns_eol = vim.api.nvim_create_namespace('pending_eol')
local ns_inline = vim.api.nvim_create_namespace('pending_inline')
---@type 'category'|'priority'|nil
local current_view = nil
---@type pending.LineMeta[]
@ -89,7 +90,9 @@ end
---@param b? integer
---@return nil
function M.clear_marks(b)
vim.api.nvim_buf_clear_namespace(b or task_bufnr, task_ns, 0, -1)
local bufnr = b or task_bufnr
vim.api.nvim_buf_clear_namespace(bufnr, ns_eol, 0, -1)
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
end
---@return nil
@ -230,12 +233,13 @@ end
---@param line_meta pending.LineMeta[]
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, ns_eol, 0, -1)
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
for i, m in ipairs(line_meta) do
local row = i - 1
if m.type == 'filter' then
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, ns_inline, row, 0, {
end_col = #line,
hl_group = 'PendingFilter',
})
@ -255,7 +259,7 @@ local function apply_extmarks(bufnr, line_meta)
for p = 1, #virt_parts - 1 do
virt_parts[p][1] = virt_parts[p][1] .. ' '
end
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, 0, {
vim.api.nvim_buf_set_extmark(bufnr, ns_eol, row, 0, {
virt_text = virt_parts,
virt_text_pos = 'eol',
})
@ -263,7 +267,7 @@ local function apply_extmarks(bufnr, line_meta)
if m.status == 'done' then
local line = vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1] or ''
local col_start = line:find('/%d+/') and select(2, line:find('/%d+/')) or 0
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, col_start, {
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, col_start, {
end_col = #line,
hl_group = 'PendingDone',
})
@ -278,18 +282,18 @@ local function apply_extmarks(bufnr, line_meta)
else
icon, icon_hl = icons.pending, 'Normal'
end
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, bracket_col, {
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, bracket_col, {
virt_text = { { '[' .. icon .. ']', icon_hl } },
virt_text_pos = 'overlay',
priority = 100,
})
elseif m.type == 'header' then
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, ns_inline, row, 0, {
end_col = #line,
hl_group = 'PendingHeader',
})
vim.api.nvim_buf_set_extmark(bufnr, task_ns, row, 0, {
vim.api.nvim_buf_set_extmark(bufnr, ns_inline, row, 0, {
virt_text = { { icons.category .. ' ', 'PendingHeader' } },
virt_text_pos = 'overlay',
priority = 100,