fix(highlight): make intra-line bg visible under line backgrounds (#192)
This commit is contained in:
parent
a1af48833b
commit
eccb4785ed
7 changed files with 53 additions and 41 deletions
|
|
@ -128,5 +128,5 @@ See the documentation for more information.
|
||||||
- [@phanen](https://github.com/phanen) - diff header highlighting, unknown
|
- [@phanen](https://github.com/phanen) - diff header highlighting, unknown
|
||||||
filetype fix, shebang/modeline detection, treesitter injection support,
|
filetype fix, shebang/modeline detection, treesitter injection support,
|
||||||
decoration provider highlighting architecture, gitsigns blame popup
|
decoration provider highlighting architecture, gitsigns blame popup
|
||||||
highlighting
|
highlighting, intra-line bg visibility fix
|
||||||
- [@tris203](https://github.com/tris203) - support for transparent backgrounds
|
- [@tris203](https://github.com/tris203) - support for transparent backgrounds
|
||||||
|
|
|
||||||
|
|
@ -956,15 +956,14 @@ Fugitive unified diff highlights: ~
|
||||||
|
|
||||||
*DiffsAddText*
|
*DiffsAddText*
|
||||||
DiffsAddText Character-level background for changed characters
|
DiffsAddText Character-level background for changed characters
|
||||||
within `+` lines. Derived by blending `diffAdded`
|
within `+` lines. Uses the raw `DiffAdd` background
|
||||||
foreground with `Normal` background at 60% alpha.
|
color. Only sets `bg`, so treesitter foreground
|
||||||
Only sets `bg`, so treesitter foreground colors show
|
colors show through.
|
||||||
through.
|
|
||||||
|
|
||||||
*DiffsDeleteText*
|
*DiffsDeleteText*
|
||||||
DiffsDeleteText Character-level background for changed characters
|
DiffsDeleteText Character-level background for changed characters
|
||||||
within `-` lines. Derived by blending `diffRemoved`
|
within `-` lines. Uses the raw `DiffDelete`
|
||||||
foreground with `Normal` background at 60% alpha.
|
background color.
|
||||||
|
|
||||||
Conflict highlights: ~
|
Conflict highlights: ~
|
||||||
*DiffsConflictOurs*
|
*DiffsConflictOurs*
|
||||||
|
|
|
||||||
|
|
@ -636,11 +636,20 @@ function M.highlight_hunk(bufnr, ns, hunk, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.highlights.background and is_diff_line then
|
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, {
|
pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, buf_line, 0, {
|
||||||
line_hl_group = line_hl,
|
end_row = buf_line,
|
||||||
number_hl_group = opts.highlights.gutter and number_hl or nil,
|
end_col = bg_end_col,
|
||||||
|
hl_group = line_hl,
|
||||||
|
hl_eol = true,
|
||||||
priority = p.line_bg,
|
priority = p.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 = p.line_bg,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_marker and line_len > pw then
|
if is_marker and line_len > pw then
|
||||||
|
|
|
||||||
|
|
@ -543,11 +543,10 @@ local function compute_highlight_groups(is_default)
|
||||||
local normal_fg = normal.fg or (dark and 0xcccccc or 0x333333)
|
local normal_fg = normal.fg or (dark and 0xcccccc or 0x333333)
|
||||||
|
|
||||||
local alpha = config.highlights.blend_alpha or 0.6
|
local alpha = config.highlights.blend_alpha or 0.6
|
||||||
local text_alpha = math.min(alpha + 0.3, 1.0)
|
|
||||||
local blended_add = blend_color(add_bg, bg, alpha)
|
local blended_add = blend_color(add_bg, bg, alpha)
|
||||||
local blended_del = blend_color(del_bg, bg, alpha)
|
local blended_del = blend_color(del_bg, bg, alpha)
|
||||||
local blended_add_text = blend_color(add_bg, bg, text_alpha)
|
local blended_add_text = add_bg
|
||||||
local blended_del_text = blend_color(del_bg, bg, text_alpha)
|
local blended_del_text = del_bg
|
||||||
|
|
||||||
local clear_hl = { default = dflt, fg = normal_fg }
|
local clear_hl = { default = dflt, fg = normal_fg }
|
||||||
if not transparent then
|
if not transparent then
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ describe('email-quoted diffs', function()
|
||||||
local line_bg_count = 0
|
local line_bg_count = 0
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and d.line_hl_group == 'DiffsAdd' then
|
if d and d.hl_group == 'DiffsAdd' then
|
||||||
line_bg_count = line_bg_count + 1
|
line_bg_count = line_bg_count + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ describe('highlight', function()
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
local has_diff_add = false
|
local has_diff_add = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_diff_add = true
|
has_diff_add = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -320,7 +320,7 @@ describe('highlight', function()
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
local has_diff_delete = false
|
local has_diff_delete = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsDelete' then
|
if mark[4] and mark[4].hl_group == 'DiffsDelete' then
|
||||||
has_diff_delete = true
|
has_diff_delete = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -362,7 +362,7 @@ describe('highlight', function()
|
||||||
delete_buffer(bufnr)
|
delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('line bg uses line_hl_group not hl_group with end_row', function()
|
it('line bg uses hl_group with hl_eol not line_hl_group', function()
|
||||||
local bufnr = create_buffer({
|
local bufnr = create_buffer({
|
||||||
'@@ -1,1 +1,2 @@',
|
'@@ -1,1 +1,2 @@',
|
||||||
' local x = 1',
|
' local x = 1',
|
||||||
|
|
@ -384,11 +384,16 @@ describe('highlight', function()
|
||||||
)
|
)
|
||||||
|
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
|
local found = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
assert.is_not_equal('DiffsAdd', d and d.hl_group)
|
if d and d.hl_group == 'DiffsAdd' then
|
||||||
assert.is_not_equal('DiffsDelete', d and d.hl_group)
|
assert.is_true(d.hl_eol)
|
||||||
|
assert.is_nil(d.line_hl_group)
|
||||||
|
found = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(found)
|
||||||
delete_buffer(bufnr)
|
delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
@ -427,7 +432,7 @@ describe('highlight', function()
|
||||||
)
|
)
|
||||||
local has_line_bg = false
|
local has_line_bg = false
|
||||||
for _, mark in ipairs(marks) do
|
for _, mark in ipairs(marks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_line_bg = true
|
has_line_bg = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -502,7 +507,7 @@ describe('highlight', function()
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
local has_diff_add = false
|
local has_diff_add = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_diff_add = true
|
has_diff_add = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -693,7 +698,7 @@ describe('highlight', function()
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
local has_diff_add = false
|
local has_diff_add = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_diff_add = true
|
has_diff_add = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -778,7 +783,7 @@ describe('highlight', function()
|
||||||
local found = false
|
local found = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
|
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
|
||||||
found = true
|
found = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -934,7 +939,7 @@ describe('highlight', function()
|
||||||
if d then
|
if d then
|
||||||
if d.hl_group == 'DiffsClear' then
|
if d.hl_group == 'DiffsClear' then
|
||||||
table.insert(priorities.clear, d.priority)
|
table.insert(priorities.clear, d.priority)
|
||||||
elseif d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete' then
|
elseif d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete' then
|
||||||
table.insert(priorities.line_bg, d.priority)
|
table.insert(priorities.line_bg, d.priority)
|
||||||
elseif d.hl_group == 'DiffsAddText' or d.hl_group == 'DiffsDeleteText' then
|
elseif d.hl_group == 'DiffsAddText' or d.hl_group == 'DiffsDeleteText' then
|
||||||
table.insert(priorities.char_bg, d.priority)
|
table.insert(priorities.char_bg, d.priority)
|
||||||
|
|
@ -1035,8 +1040,8 @@ describe('highlight', function()
|
||||||
local line_bgs = {}
|
local line_bgs = {}
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
|
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
|
||||||
line_bgs[mark[2]] = d.line_hl_group
|
line_bgs[mark[2]] = d.hl_group
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert.is_nil(line_bgs[1])
|
assert.is_nil(line_bgs[1])
|
||||||
|
|
@ -1232,8 +1237,8 @@ describe('highlight', function()
|
||||||
local marker_text = {}
|
local marker_text = {}
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
|
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
|
||||||
line_bgs[mark[2]] = d.line_hl_group
|
line_bgs[mark[2]] = d.hl_group
|
||||||
end
|
end
|
||||||
if d and d.number_hl_group then
|
if d and d.number_hl_group then
|
||||||
gutter_hls[mark[2]] = d.number_hl_group
|
gutter_hls[mark[2]] = d.number_hl_group
|
||||||
|
|
@ -1376,7 +1381,7 @@ describe('highlight', function()
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[2] == row then
|
if mark[2] == row then
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d.line_hl_group then
|
if d.hl_group and d.hl_eol then
|
||||||
line_hl_count = line_hl_count + 1
|
line_hl_count = line_hl_count + 1
|
||||||
end
|
end
|
||||||
if d.number_hl_group then
|
if d.number_hl_group then
|
||||||
|
|
@ -1387,7 +1392,7 @@ describe('highlight', function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert.are.equal(1, line_hl_count, 'row ' .. row .. ' has duplicate line_hl_group')
|
assert.are.equal(1, line_hl_count, 'row ' .. row .. ' has duplicate line bg')
|
||||||
assert.are.equal(1, number_hl_count, 'row ' .. row .. ' has duplicate number_hl_group')
|
assert.are.equal(1, number_hl_count, 'row ' .. row .. ' has duplicate number_hl_group')
|
||||||
assert.is_true(intra_count <= 1, 'row ' .. row .. ' has duplicate intra extmarks')
|
assert.is_true(intra_count <= 1, 'row ' .. row .. ' has duplicate intra extmarks')
|
||||||
end
|
end
|
||||||
|
|
@ -1429,18 +1434,18 @@ describe('highlight', function()
|
||||||
|
|
||||||
local extmarks = get_extmarks(bufnr)
|
local extmarks = get_extmarks(bufnr)
|
||||||
local has_ts = false
|
local has_ts = false
|
||||||
local line_hl_count = 0
|
local line_bg_count = 0
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and d.hl_group and d.hl_group:match('^@.*%.lua$') then
|
if d and d.hl_group and d.hl_group:match('^@.*%.lua$') then
|
||||||
has_ts = true
|
has_ts = true
|
||||||
end
|
end
|
||||||
if d and d.line_hl_group then
|
if d and d.hl_group and d.hl_eol then
|
||||||
line_hl_count = line_hl_count + 1
|
line_bg_count = line_bg_count + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert.is_true(has_ts)
|
assert.is_true(has_ts)
|
||||||
assert.are.equal(1, line_hl_count)
|
assert.are.equal(1, line_bg_count)
|
||||||
delete_buffer(bufnr)
|
delete_buffer(bufnr)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,7 @@ describe('integration', function()
|
||||||
local extmarks = get_extmarks(bufnr, ns)
|
local extmarks = get_extmarks(bufnr, ns)
|
||||||
local has_diff_add = false
|
local has_diff_add = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_diff_add = true
|
has_diff_add = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -275,7 +275,7 @@ describe('integration', function()
|
||||||
local extmarks = get_extmarks(bufnr, ns)
|
local extmarks = get_extmarks(bufnr, ns)
|
||||||
local has_diff_delete = false
|
local has_diff_delete = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsDelete' then
|
if mark[4] and mark[4].hl_group == 'DiffsDelete' then
|
||||||
has_diff_delete = true
|
has_diff_delete = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
@ -302,10 +302,10 @@ describe('integration', function()
|
||||||
local has_add = false
|
local has_add = false
|
||||||
local has_delete = false
|
local has_delete = false
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
|
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
|
||||||
has_add = true
|
has_add = true
|
||||||
end
|
end
|
||||||
if mark[4] and mark[4].line_hl_group == 'DiffsDelete' then
|
if mark[4] and mark[4].hl_group == 'DiffsDelete' then
|
||||||
has_delete = true
|
has_delete = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -334,8 +334,8 @@ describe('integration', function()
|
||||||
local line_bgs = {}
|
local line_bgs = {}
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
|
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
|
||||||
line_bgs[mark[2]] = d.line_hl_group
|
line_bgs[mark[2]] = d.hl_group
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert.is_nil(line_bgs[1])
|
assert.is_nil(line_bgs[1])
|
||||||
|
|
@ -417,10 +417,10 @@ describe('integration', function()
|
||||||
local del_lines = {}
|
local del_lines = {}
|
||||||
for _, mark in ipairs(extmarks) do
|
for _, mark in ipairs(extmarks) do
|
||||||
local d = mark[4]
|
local d = mark[4]
|
||||||
if d and d.line_hl_group == 'DiffsAdd' then
|
if d and d.hl_group == 'DiffsAdd' then
|
||||||
add_lines[mark[2]] = true
|
add_lines[mark[2]] = true
|
||||||
end
|
end
|
||||||
if d and d.line_hl_group == 'DiffsDelete' then
|
if d and d.hl_group == 'DiffsDelete' then
|
||||||
del_lines[mark[2]] = true
|
del_lines[mark[2]] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue