feat(highlight): add configurable blend alpha
Problem: the character-level blend intensity was hardcoded to 0.6, giving users no way to tune how strongly changed characters stand out from the line-level background. Solution: add highlights.blend_alpha config option (number, 0-1, default 0.6) with type validation and range check.
This commit is contained in:
parent
8e0c41bf6b
commit
b7477e3af2
2 changed files with 20 additions and 2 deletions
|
|
@ -56,6 +56,7 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
|||
highlights = {
|
||||
background = true,
|
||||
gutter = true,
|
||||
blend_alpha = 0.6,
|
||||
context = {
|
||||
enabled = true,
|
||||
lines = 25,
|
||||
|
|
@ -117,6 +118,13 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
|||
Highlight line numbers with matching colors.
|
||||
Only visible if line numbers are enabled.
|
||||
|
||||
{blend_alpha} (number, default: 0.6)
|
||||
Alpha value for character-level blend intensity.
|
||||
Controls how strongly changed characters stand
|
||||
out from the line-level background. Must be
|
||||
between 0 and 1 (inclusive). Higher values
|
||||
produce more vivid character-level highlights.
|
||||
|
||||
{context} (table, default: see below)
|
||||
Syntax parsing context options.
|
||||
See |diffs.ContextConfig| for fields.
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
---@class diffs.Highlights
|
||||
---@field background boolean
|
||||
---@field gutter boolean
|
||||
---@field blend_alpha? number
|
||||
---@field context diffs.ContextConfig
|
||||
---@field treesitter diffs.TreesitterConfig
|
||||
---@field vim diffs.VimConfig
|
||||
|
|
@ -192,8 +193,9 @@ local function compute_highlight_groups()
|
|||
local blended_add = blend_color(add_bg, bg, 0.4)
|
||||
local blended_del = blend_color(del_bg, bg, 0.4)
|
||||
|
||||
local blended_add_text = blend_color(add_fg, bg, 0.6)
|
||||
local blended_del_text = blend_color(del_fg, bg, 0.6)
|
||||
local alpha = config.highlights.blend_alpha or 0.6
|
||||
local blended_add_text = blend_color(add_fg, bg, alpha)
|
||||
local blended_del_text = blend_color(del_fg, bg, alpha)
|
||||
|
||||
vim.api.nvim_set_hl(0, 'DiffsClear', { default = true, fg = normal.fg or 0xc0c0c0 })
|
||||
vim.api.nvim_set_hl(0, 'DiffsAdd', { default = true, bg = blended_add })
|
||||
|
|
@ -248,6 +250,7 @@ local function init()
|
|||
vim.validate({
|
||||
['highlights.background'] = { opts.highlights.background, 'boolean', true },
|
||||
['highlights.gutter'] = { opts.highlights.gutter, 'boolean', true },
|
||||
['highlights.blend_alpha'] = { opts.highlights.blend_alpha, 'number', true },
|
||||
['highlights.context'] = { opts.highlights.context, 'table', true },
|
||||
['highlights.treesitter'] = { opts.highlights.treesitter, 'table', true },
|
||||
['highlights.vim'] = { opts.highlights.vim, 'table', true },
|
||||
|
|
@ -348,6 +351,13 @@ local function init()
|
|||
then
|
||||
error('diffs: highlights.intra.max_lines must be >= 1')
|
||||
end
|
||||
if
|
||||
opts.highlights
|
||||
and opts.highlights.blend_alpha
|
||||
and (opts.highlights.blend_alpha < 0 or opts.highlights.blend_alpha > 1)
|
||||
then
|
||||
error('diffs: highlights.blend_alpha must be >= 0 and <= 1')
|
||||
end
|
||||
|
||||
config = vim.tbl_deep_extend('force', default_config, opts)
|
||||
log.set_enabled(config.debug)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue