fix(buffer): escape hyphens in infer_status Lua patterns (#119)
* fix(buffer): escape hyphens in `infer_status` Lua patterns Problem: `infer_status` used `/-` in its Lua patterns, which is a lazy quantifier on `/` rather than a literal hyphen. This caused the function to always return `nil` for lines with an `/id/` prefix, so status was never inferred from buffer text during `reapply_dirty_inline`. Solution: escape hyphens as `%-` in both patterns. Also add debug logging to `on_bytes`, `reapply_dirty_inline`, `apply_extmarks`, and the `TextChanged`/`TextChangedI`/`InsertLeave` autocmds. * ci: format
This commit is contained in:
parent
a38be10e67
commit
1eb2e49096
2 changed files with 34 additions and 2 deletions
|
|
@ -185,7 +185,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
|
||||||
|
|
@ -205,12 +205,22 @@ function M.reapply_dirty_inline(bufnr)
|
||||||
if not next(_dirty_rows) then
|
if not next(_dirty_rows) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
log.debug(('reapply_dirty: rows=%s'):format(vim.inspect(vim.tbl_keys(_dirty_rows))))
|
||||||
local icons = config.get().icons
|
local icons = config.get().icons
|
||||||
for row in pairs(_dirty_rows) do
|
for row in pairs(_dirty_rows) do
|
||||||
local m = _meta[row]
|
local m = _meta[row]
|
||||||
if m and m.type == 'task' then
|
if m and m.type == 'task' then
|
||||||
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1] or ''
|
local line = vim.api.nvim_buf_get_lines(bufnr, row - 1, row, false)[1] or ''
|
||||||
|
local old_status = m.status
|
||||||
m.status = infer_status(line) or m.status
|
m.status = infer_status(line) or m.status
|
||||||
|
log.debug(
|
||||||
|
('reapply_dirty: row=%d line=%q old_status=%s new_status=%s'):format(
|
||||||
|
row,
|
||||||
|
line,
|
||||||
|
tostring(old_status),
|
||||||
|
tostring(m.status)
|
||||||
|
)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
if m then
|
if m then
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, row - 1, row)
|
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, row - 1, row)
|
||||||
|
|
@ -228,7 +238,7 @@ function M.attach_bytes(bufnr)
|
||||||
end
|
end
|
||||||
_on_bytes_active = true
|
_on_bytes_active = true
|
||||||
vim.api.nvim_buf_attach(bufnr, false, {
|
vim.api.nvim_buf_attach(bufnr, false, {
|
||||||
on_bytes = function(_, buf, _, start_row, _, _, old_end_row, _, _, new_end_row, _, _)
|
on_bytes = function(_, buf, _, start_row, start_col, _, old_end_row, _, _, new_end_row, _, _)
|
||||||
if buf ~= task_bufnr then
|
if buf ~= task_bufnr then
|
||||||
_on_bytes_active = false
|
_on_bytes_active = false
|
||||||
return true
|
return true
|
||||||
|
|
@ -237,13 +247,24 @@ function M.attach_bytes(bufnr)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local delta = new_end_row - old_end_row
|
local delta = new_end_row - old_end_row
|
||||||
|
log.debug(
|
||||||
|
('on_bytes: start_row=%d start_col=%d old_end=%d new_end=%d delta=%d'):format(
|
||||||
|
start_row,
|
||||||
|
start_col,
|
||||||
|
old_end_row,
|
||||||
|
new_end_row,
|
||||||
|
delta
|
||||||
|
)
|
||||||
|
)
|
||||||
if delta > 0 then
|
if delta > 0 then
|
||||||
for _ = 1, delta do
|
for _ = 1, delta do
|
||||||
|
log.debug(('on_bytes: insert meta at %d'):format(start_row + 2))
|
||||||
table.insert(_meta, start_row + 2, { type = 'task' })
|
table.insert(_meta, start_row + 2, { type = 'task' })
|
||||||
end
|
end
|
||||||
elseif delta < 0 then
|
elseif delta < 0 then
|
||||||
for _ = 1, -delta do
|
for _ = 1, -delta do
|
||||||
if _meta[start_row + 2] then
|
if _meta[start_row + 2] then
|
||||||
|
log.debug(('on_bytes: remove meta at %d'):format(start_row + 2))
|
||||||
table.remove(_meta, start_row + 2)
|
table.remove(_meta, start_row + 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -251,6 +272,10 @@ function M.attach_bytes(bufnr)
|
||||||
for r = start_row + 1, start_row + 1 + math.max(0, new_end_row) do
|
for r = start_row + 1, start_row + 1 + math.max(0, new_end_row) do
|
||||||
_dirty_rows[r] = true
|
_dirty_rows[r] = true
|
||||||
end
|
end
|
||||||
|
log.debug(('on_bytes: dirty rows=%s'):format(vim.inspect(vim.tbl_keys(_dirty_rows))))
|
||||||
|
for i, m in ipairs(_meta) do
|
||||||
|
log.debug(('on_bytes: _meta[%d] type=%s status=%s'):format(i, m.type, tostring(m.status)))
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
@ -496,7 +521,11 @@ local function apply_extmarks(bufnr, line_meta)
|
||||||
local eol_segments = parse_eol_format(cfg.view.eol_format or '%c %r %d')
|
local eol_segments = parse_eol_format(cfg.view.eol_format or '%c %r %d')
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_eol, 0, -1)
|
vim.api.nvim_buf_clear_namespace(bufnr, ns_eol, 0, -1)
|
||||||
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
|
vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, 0, -1)
|
||||||
|
log.debug(('apply_extmarks: full render, %d lines'):format(#line_meta))
|
||||||
for i, m in ipairs(line_meta) do
|
for i, m in ipairs(line_meta) do
|
||||||
|
log.debug(
|
||||||
|
('apply_extmarks: row=%d type=%s status=%s'):format(i - 1, m.type, tostring(m.status))
|
||||||
|
)
|
||||||
local row = i - 1
|
local row = i - 1
|
||||||
if m.type == 'task' then
|
if m.type == 'task' then
|
||||||
local virt_parts = build_eol_virt(eol_segments, m, icons)
|
local virt_parts = build_eol_virt(eol_segments, m, icons)
|
||||||
|
|
|
||||||
|
|
@ -268,6 +268,7 @@ function M._setup_autocmds(bufnr)
|
||||||
if not vim.bo[bufnr].modified then
|
if not vim.bo[bufnr].modified then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
log.debug('autocmd: TextChangedI')
|
||||||
for row in pairs(buffer.dirty_rows()) do
|
for row in pairs(buffer.dirty_rows()) do
|
||||||
buffer.clear_inline_row(bufnr, row)
|
buffer.clear_inline_row(bufnr, row)
|
||||||
end
|
end
|
||||||
|
|
@ -280,6 +281,7 @@ function M._setup_autocmds(bufnr)
|
||||||
if not vim.bo[bufnr].modified then
|
if not vim.bo[bufnr].modified then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
log.debug('autocmd: TextChanged')
|
||||||
buffer.reapply_dirty_inline(bufnr)
|
buffer.reapply_dirty_inline(bufnr)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
@ -288,6 +290,7 @@ function M._setup_autocmds(bufnr)
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
if vim.bo[bufnr].modified then
|
if vim.bo[bufnr].modified then
|
||||||
|
log.debug('autocmd: InsertLeave')
|
||||||
buffer.reapply_dirty_inline(bufnr)
|
buffer.reapply_dirty_inline(bufnr)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue