Skip to content

fix(highlight): make intra-line bg visible under line backgrounds (#192)#194

Merged
barrettruth merged 3 commits intomainfrom
fix/intra-line-bg-visibility
Mar 15, 2026
Merged

fix(highlight): make intra-line bg visible under line backgrounds (#192)#194
barrettruth merged 3 commits intomainfrom
fix/intra-line-bg-visibility

Conversation

@barrettruth
Copy link
Owner

Problem

line_hl_group bg unconditionally overrides hl_group bg regardless of priority (neovim/neovim#31151). DiffsAddText/DiffsDeleteText intra-line highlights at p201 were invisible under DiffsAdd/DiffsDelete line backgrounds at p200 because they operate on separate Neovim stacking layers.

Solution

Replace line_hl_group with hl_group + hl_eol for line backgrounds, putting them on the same layer as intra-line highlights so priority stacking works. Use multiline extmarks (end_row = buf_line + 1, end_col = 0) since Neovim requires end_row > start_row for hl_eol. Add clear_ns_by_start helper that deletes extmarks by start position only, preventing adjacent hunk clearing from killing multiline bg extmarks whose end_row bleeds into the cleared range. Guard carry_forward_highlighted with #entry.hunks == #hunks to force full clear when hunks are added/removed, preventing stale extmarks from repositioned deleted lines.

Credit to @phanen for identifying the hl_eol requirement (PR #81).

…n clearing

Problem: single-row extmarks (`end_row = buf_line, end_col = len`) do
not trigger `hl_eol` — Neovim requires `end_row > start_row`. Line
backgrounds stopped at the last character instead of extending to the
window edge.

Solution: use `end_row = buf_line + 1, end_col = 0` for line bg
extmarks. Replace per-hunk `nvim_buf_clear_namespace` with
`clear_ns_by_start` that queries extmarks by start position only,
so adjacent hunks' trailing `end_row` is never killed.
Problem: when fugitive collapses a diff section, Neovim repositions
extmarks from deleted lines onto surviving lines. `carry_forward_highlighted`
matched hunks by content only, carrying forward the "highlighted" flag
for stable hunks and leaving stale extmarks from removed hunks uncleaned.

Solution: add `#entry.hunks == #hunks` guard to the carry-forward
precondition. When hunk count changes, skip carry-forward and set
`pending_clear = true` so `on_buf` wipes all extmarks before
`on_win` re-highlights visible hunks.
@barrettruth barrettruth force-pushed the fix/intra-line-bg-visibility branch from 60785c3 to aeb74e0 Compare March 15, 2026 16:38
@barrettruth
Copy link
Owner Author

@phanen take latest main and let me know if this fixes it.

@barrettruth barrettruth merged commit 6601b38 into main Mar 15, 2026
7 checks passed
@barrettruth barrettruth deleted the fix/intra-line-bg-visibility branch March 15, 2026 16:39
@phanen
Copy link

phanen commented Mar 16, 2026

Ok, it did fix. Thanks a lot for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants