fix(init): fix cursor position when navigating from quickfix

Problem: `:Pending due` quickfix items landed on line 1 instead of
the task line. The `BufEnter` redirect branch captured cursor before
quickfix had positioned it in the new window, so the stale position
was used when transferring focus back to the registered pending window.

Solution: move cursor capture inside `vim.schedule` so it reads after
quickfix navigation has completed. Also guard `clear_marks` behind a
`modified` check so extmarks are only cleared on actual edits.
This commit is contained in:
Barrett Ruth 2026-03-07 01:36:07 -05:00
parent 5fe6dcecad
commit c8e049e02d

View file

@ -227,14 +227,18 @@ function M._setup_autocmds(bufnr)
local cur_win = vim.api.nvim_get_current_win()
local tw = buffer.winid()
if tw and vim.api.nvim_win_is_valid(tw) and cur_win ~= tw then
local cursor = vim.api.nvim_win_get_cursor(cur_win)
vim.schedule(function()
local cursor = vim.api.nvim_win_is_valid(cur_win)
and vim.api.nvim_win_get_cursor(cur_win)
or nil
if vim.api.nvim_win_is_valid(cur_win) and #vim.api.nvim_list_wins() > 1 then
pcall(vim.api.nvim_win_close, cur_win, false)
end
if vim.api.nvim_win_is_valid(tw) then
vim.api.nvim_set_current_win(tw)
pcall(vim.api.nvim_win_set_cursor, tw, cursor)
if cursor then
pcall(vim.api.nvim_win_set_cursor, tw, cursor)
end
end
end)
return
@ -252,7 +256,9 @@ function M._setup_autocmds(bufnr)
group = group,
buffer = bufnr,
callback = function()
buffer.clear_marks(bufnr)
if vim.bo[bufnr].modified then
buffer.clear_marks(bufnr)
end
end,
})
vim.api.nvim_create_autocmd('WinClosed', {