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:
parent
5fe6dcecad
commit
c8e049e02d
1 changed files with 9 additions and 3 deletions
|
|
@ -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', {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue