From b7477e3af24ec499cfedf5cfcf4b3db2dda24653 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 7 Feb 2026 15:46:47 -0500 Subject: [PATCH] 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. --- doc/diffs.nvim.txt | 8 ++++++++ lua/diffs/init.lua | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/diffs.nvim.txt b/doc/diffs.nvim.txt index 7704b5b..cf03a6f 100644 --- a/doc/diffs.nvim.txt +++ b/doc/diffs.nvim.txt @@ -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. diff --git a/lua/diffs/init.lua b/lua/diffs/init.lua index 14a4c13..3397bc1 100644 --- a/lua/diffs/init.lua +++ b/lua/diffs/init.lua @@ -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)