Skip to content

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

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

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

Conversation

@barrettruth
Copy link
Owner

@barrettruth barrettruth commented Mar 14, 2026

tbh unsure how to test this well and not in the perfect mood for it... make an issue tracking the upstream one.

this should work for now

Closes #191 (thanks @phanen).

@barrettruth barrettruth mentioned this pull request Mar 14, 2026
Problem: `line_hl_group` bg unconditionally overrides `hl_group` bg
regardless of priority (neovim/neovim#31151). `DiffsAddText`/
`DiffsDeleteText` at p201 were invisible under `DiffsAdd`/`DiffsDelete`
`line_hl_group` at p200 because they operate on separate stacking layers.

Solution: replace `line_hl_group` with `hl_group` + `hl_eol` +
`end_col` for line backgrounds, putting them on the same layer as
intra-line highlights so priority governs stacking. Use single-row
extmarks (`end_row = buf_line`) to avoid the adjacent-hunk clearing
bug. Split `number_hl_group` into a separate extmark. Use raw
`DiffAdd.bg`/`DiffDelete.bg` for `DiffsAddText`/`DiffsDeleteText`
instead of alpha-blending toward Normal.bg, which produced
indistinguishable colors on dark themes.
@barrettruth barrettruth force-pushed the fix/intra-line-bg-visibility branch from a7d0c04 to 8c41c70 Compare March 14, 2026 01:23
@barrettruth barrettruth merged commit eccb478 into main Mar 14, 2026
7 checks passed
@barrettruth barrettruth deleted the fix/intra-line-bg-visibility branch March 14, 2026 01:25
@phanen
Copy link

phanen commented Mar 15, 2026

it don't highlight the whole line for me:
image

Not sure what's end_col here, but this can make this work as expected for me:

diff --git a/lua/diffs/highlight.lua b/lua/diffs/highlight.lua
index 445354a..1045d81 100644
--- a/lua/diffs/highlight.lua
+++ b/lua/diffs/highlight.lua
@@ -636,10 +636,8 @@ function M.highlight_hunk(bufnr, ns, hunk, opts)
       end
 
       if opts.highlights.background and is_diff_line then
-        local bg_end_col = raw_len or (line_len + qw)
         pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, {
-          end_row = buf_line,
-          end_col = bg_end_col,
+          end_row = buf_line + 1,
           hl_group = line_hl,
           hl_eol = true,
           priority = p.line_bg,
image

@barrettruth
Copy link
Owner Author

Damn. We're definitely looping on this. My bad...

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