fix: clear stale gutter extmarks after fugitive section toggle
Problem: Repeatedly toggling `=` in fugitive left green gutter
extmarks on lines between sections. Two issues combined:
(1) carry_forward_highlighted returned an empty table (truthy in
Lua) when zero hunks matched, so pending_clear stayed false and
compressed extmarks from deleted diff lines were never cleared.
(2) The namespace clear in on_buf's pending_clear path was removed
in 2feb8a8, so even when pending_clear was true the extmarks
survived.
Solution: Return nil from carry_forward_highlighted when no hunks
were carried forward, so pending_clear is correctly set to true.
Restore nvim_buf_clear_namespace in on_buf's pending_clear block.
Add process_pending_clear test helper and spec coverage.
This commit is contained in:
parent
6040c054cb
commit
330b3fdc28
2 changed files with 40 additions and 1 deletions
|
|
@ -288,6 +288,9 @@ local function carry_forward_highlighted(old_entry, new_hunks)
|
|||
old_n,
|
||||
new_n
|
||||
)
|
||||
if next(highlighted) == nil then
|
||||
return nil
|
||||
end
|
||||
return highlighted
|
||||
end
|
||||
|
||||
|
|
@ -729,6 +732,7 @@ local function init()
|
|||
ensure_cache(bufnr)
|
||||
local entry = hunk_cache[bufnr]
|
||||
if entry and entry.pending_clear then
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
|
||||
entry.highlighted = {}
|
||||
entry.pending_clear = false
|
||||
end
|
||||
|
|
@ -927,12 +931,22 @@ function M.get_conflict_config()
|
|||
return config.conflict
|
||||
end
|
||||
|
||||
local function process_pending_clear(bufnr)
|
||||
local entry = hunk_cache[bufnr]
|
||||
if entry and entry.pending_clear then
|
||||
vim.api.nvim_buf_clear_namespace(bufnr, ns, 0, -1)
|
||||
entry.highlighted = {}
|
||||
entry.pending_clear = false
|
||||
end
|
||||
end
|
||||
|
||||
M._test = {
|
||||
find_visible_hunks = find_visible_hunks,
|
||||
hunk_cache = hunk_cache,
|
||||
ensure_cache = ensure_cache,
|
||||
invalidate_cache = invalidate_cache,
|
||||
hunks_eq = hunks_eq,
|
||||
process_pending_clear = process_pending_clear,
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue