fix(buffer): fix stale extmarks, duplicate window, and fold state loss (#92)
Problem: Deleting lines (`dd`, `dat`, `d3j`) left extmarks stranded on adjacent rows since `render()` only clears and reapplies marks on `:w`. Quickfix `<CR>` opened the pending buffer in a second window because `BufEnter` did not redirect to `task_winid`. Category fold state was lost across `<Tab>/<Tab>` view toggles because `render()` overwrote the saved state with an empty snapshot taken while folds were disabled. Solution: Add a `TextChanged`/`TextChangedI` autocmd that clears the extmark namespace immediately on any edit. Fix `BufEnter` to close duplicate windows and redirect focus to `task_winid`, updating it when stale. Fix `snapshot_folds` to skip if a state is already saved, and `restore_folds` to always clear the saved state; snapshot in `toggle_view` before the view flips so the state survives the round-trip.
This commit is contained in:
parent
c392874311
commit
559ab863a8
2 changed files with 43 additions and 1 deletions
|
|
@ -224,12 +224,37 @@ function M._setup_autocmds(bufnr)
|
|||
group = group,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
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()
|
||||
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)
|
||||
end
|
||||
end)
|
||||
return
|
||||
end
|
||||
if not tw or not vim.api.nvim_win_is_valid(tw) then
|
||||
buffer.update_winid(cur_win)
|
||||
end
|
||||
if not vim.bo[bufnr].modified then
|
||||
get_store():load()
|
||||
buffer.render(bufnr)
|
||||
end
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd({ 'TextChanged', 'TextChangedI' }, {
|
||||
group = group,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
buffer.clear_marks(bufnr)
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_create_autocmd('WinClosed', {
|
||||
group = group,
|
||||
callback = function(ev)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue