diff --git a/lua/diffs/highlight.lua b/lua/diffs/highlight.lua index 9582910..bf9063d 100644 --- a/lua/diffs/highlight.lua +++ b/lua/diffs/highlight.lua @@ -458,12 +458,17 @@ function M.highlight_hunk(bufnr, ns, hunk, opts) if opts.highlights.background and is_diff_line then 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_eol = true, - number_hl_group = opts.highlights.gutter and number_hl or nil, 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 if char_spans_by_line[i] then diff --git a/spec/highlight_spec.lua b/spec/highlight_spec.lua index 5fd1fa5..2f95d02 100644 --- a/spec/highlight_spec.lua +++ b/spec/highlight_spec.lua @@ -800,6 +800,72 @@ describe('highlight', function() delete_buffer(bufnr) 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() local bufnr = create_buffer({ '@@ -1,2 +1,1 @@',