From 666690ad488960158b3661885bd1b22becaef8ff Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 9 Mar 2026 00:12:48 -0400 Subject: [PATCH] fix(buffer): correct extmark drift on `open_line` above/below done tasks Problem: `open_line` used `nvim_buf_set_lines` which triggered `on_bytes` with a `start_row` offset designed for native `o`/`O` keypresses. The `_meta` entry was inserted one position too late, causing the done task's `PendingDone` highlight to attach to the new blank line instead. Solution: suppress `on_bytes` during `open_line` by reusing the `_rendering` guard, insert the meta entry at the correct position, and immediately reapply inline extmarks for the affected rows. --- lua/pending/buffer.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lua/pending/buffer.lua b/lua/pending/buffer.lua index 5d18e1f..c543c7d 100644 --- a/lua/pending/buffer.lua +++ b/lua/pending/buffer.lua @@ -345,8 +345,25 @@ function M.open_line(above) end local row = vim.api.nvim_win_get_cursor(0)[1] local insert_row = above and (row - 1) or row + local meta_pos = insert_row + 1 + + _rendering = true vim.bo[bufnr].modifiable = true vim.api.nvim_buf_set_lines(bufnr, insert_row, insert_row, false, { '- [ ] ' }) + _rendering = false + + table.insert(_meta, meta_pos, { type = 'task' }) + + local icons = config.get().icons + local total = vim.api.nvim_buf_line_count(bufnr) + for r = meta_pos, math.min(meta_pos + 1, total) do + vim.api.nvim_buf_clear_namespace(bufnr, ns_inline, r - 1, r) + local m = _meta[r] + if m then + apply_inline_row(bufnr, r - 1, m, icons) + end + end + vim.api.nvim_win_set_cursor(0, { insert_row + 1, 6 }) vim.cmd('startinsert!') end