fix(highlight): make hl_eol work on background extmarks
Problem: hl_eol requires a multiline extmark to extend the background past end-of-line. The extmark used end_col = line_len on the same row, so it was single-line and hl_eol was effectively a no-op. Solution: replace end_col with end_row targeting the next line so the extmark is multiline and hl_eol takes effect. Split number_hl_group into a separate extmark to prevent it bleeding to adjacent lines.
This commit is contained in:
parent
af37d25f25
commit
011db2f8b3
2 changed files with 73 additions and 2 deletions
|
|
@ -458,12 +458,17 @@ function M.highlight_hunk(bufnr, ns, hunk, opts)
|
||||||
|
|
||||||
if opts.highlights.background and is_diff_line then
|
if opts.highlights.background and is_diff_line then
|
||||||
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, {
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, {
|
||||||
end_col = line_len,
|
end_row = buf_line + 1,
|
||||||
hl_group = line_hl,
|
hl_group = line_hl,
|
||||||
hl_eol = true,
|
hl_eol = true,
|
||||||
number_hl_group = opts.highlights.gutter and number_hl or nil,
|
|
||||||
priority = PRIORITY_LINE_BG,
|
priority = PRIORITY_LINE_BG,
|
||||||
})
|
})
|
||||||
|
if opts.highlights.gutter then
|
||||||
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, {
|
||||||
|
number_hl_group = number_hl,
|
||||||
|
priority = PRIORITY_LINE_BG,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if char_spans_by_line[i] then
|
if char_spans_by_line[i] then
|
||||||
|
|
|
||||||
|
|
@ -800,6 +800,72 @@ describe('highlight', function()
|
||||||
delete_buffer(bufnr)
|
delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('hl_eol background extmarks are multiline so hl_eol takes effect', function()
|
||||||
|
local bufnr = create_buffer({
|
||||||
|
'@@ -1,2 +1,1 @@',
|
||||||
|
'-local x = 1',
|
||||||
|
'+local y = 2',
|
||||||
|
})
|
||||||
|
|
||||||
|
local hunk = {
|
||||||
|
filename = 'test.lua',
|
||||||
|
lang = 'lua',
|
||||||
|
start_line = 1,
|
||||||
|
lines = { '-local x = 1', '+local y = 2' },
|
||||||
|
}
|
||||||
|
|
||||||
|
highlight.highlight_hunk(
|
||||||
|
bufnr,
|
||||||
|
ns,
|
||||||
|
hunk,
|
||||||
|
default_opts({ highlights = { background = true } })
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
local d = mark[4]
|
||||||
|
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
|
||||||
|
assert.is_true(d.end_row > mark[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('number_hl_group does not bleed to adjacent lines', function()
|
||||||
|
local bufnr = create_buffer({
|
||||||
|
'@@ -1,3 +1,3 @@',
|
||||||
|
' local a = 0',
|
||||||
|
'-local x = 1',
|
||||||
|
'+local y = 2',
|
||||||
|
' local b = 3',
|
||||||
|
})
|
||||||
|
|
||||||
|
local hunk = {
|
||||||
|
filename = 'test.lua',
|
||||||
|
lang = 'lua',
|
||||||
|
start_line = 1,
|
||||||
|
lines = { ' local a = 0', '-local x = 1', '+local y = 2', ' local b = 3' },
|
||||||
|
}
|
||||||
|
|
||||||
|
highlight.highlight_hunk(
|
||||||
|
bufnr,
|
||||||
|
ns,
|
||||||
|
hunk,
|
||||||
|
default_opts({ highlights = { background = true, gutter = true } })
|
||||||
|
)
|
||||||
|
|
||||||
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
for _, mark in ipairs(extmarks) do
|
||||||
|
local d = mark[4]
|
||||||
|
if d and d.number_hl_group then
|
||||||
|
local start_row = mark[2]
|
||||||
|
local end_row = d.end_row or start_row
|
||||||
|
assert.are.equal(start_row, end_row)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
delete_buffer(bufnr)
|
||||||
|
end)
|
||||||
|
|
||||||
it('line bg priority > DiffsClear priority', function()
|
it('line bg priority > DiffsClear priority', function()
|
||||||
local bufnr = create_buffer({
|
local bufnr = create_buffer({
|
||||||
'@@ -1,2 +1,1 @@',
|
'@@ -1,2 +1,1 @@',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue