From fedf6bc236ed2177f39ba1a40a74a996a2ad4f45 Mon Sep 17 00:00:00 2001 From: Leonardo Laurindo Date: Sat, 15 Aug 2026 10:20:08 -0300 Subject: [PATCH] feat: add word_del_strikethrough config option Allow disabling the strikethrough on deleted words within changed lines. Defaults to true, preserving current behavior. --- doc/inline-diff.txt | 10 +++++++++- lua/inline-diff/highlight.lua | 8 +++++++- lua/inline-diff/init.lua | 3 +++ tests/highlight_spec.lua | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/inline-diff.txt b/doc/inline-diff.txt index 7f06579..5612757 100644 --- a/doc/inline-diff.txt +++ b/doc/inline-diff.txt @@ -27,6 +27,7 @@ Call `setup()` once in your config. All arguments are optional: >lua require("inline-diff").setup({ debounce_ms = 150, -- ms to wait after last keystroke + word_del_strikethrough = true, -- strikethrough deleted words in changed lines }) < @@ -38,6 +39,12 @@ Options ~ Milliseconds to wait after the last keystroke before recomputing the diff. Raise this value if you notice CPU usage during fast typing. + word_del_strikethrough *inline-diff-config-word_del_strikethrough* + Type: `boolean`, Default: `true` + When `true`, words deleted within a changed line are shown with a + strikethrough. Set to `false` to render them with the same solid + background as fully removed lines. + ============================================================================== COMMANDS *inline-diff-commands* @@ -104,7 +111,8 @@ Colors are derived automatically from your colorscheme's `DiffAdd` and InlineDiffWordDel *hl-InlineDiffWordDel* Background of individual deleted words in virtual lines - (brighter than InlineDiffDelete, strikethrough). + (brighter than InlineDiffDelete; strikethrough unless + `word_del_strikethrough` is `false`). Override any group after `setup()` or inside a `ColorScheme` autocmd: >lua diff --git a/lua/inline-diff/highlight.lua b/lua/inline-diff/highlight.lua index 983eabe..58f6553 100644 --- a/lua/inline-diff/highlight.lua +++ b/lua/inline-diff/highlight.lua @@ -1,5 +1,7 @@ local M = {} +M.word_del_strikethrough = true + function M._rgb_to_hsl(rgb) local r = bit.rshift(bit.band(rgb, 0xFF0000), 16) / 255 local g = bit.rshift(bit.band(rgb, 0x00FF00), 8) / 255 @@ -90,7 +92,11 @@ function M.define() vim.api.nvim_set_hl(0, "InlineDiffAdd", { bg = add_bg, fg = M._contrast_fg(add_bg) }) vim.api.nvim_set_hl(0, "InlineDiffDelete", { bg = del_bg, fg = M._contrast_fg(del_bg) }) vim.api.nvim_set_hl(0, "InlineDiffWordAdd", { bg = word_add_bg, fg = M._contrast_fg(word_add_bg) }) - vim.api.nvim_set_hl(0, "InlineDiffWordDel", { bg = word_del_bg, fg = M._contrast_fg(word_del_bg), strikethrough = true }) + local word_del_hl = { bg = word_del_bg, fg = M._contrast_fg(word_del_bg) } + if M.word_del_strikethrough ~= false then + word_del_hl.strikethrough = true + end + vim.api.nvim_set_hl(0, "InlineDiffWordDel", word_del_hl) end function M.setup_autocmd() diff --git a/lua/inline-diff/init.lua b/lua/inline-diff/init.lua index d1ed50b..ed6ef92 100644 --- a/lua/inline-diff/init.lua +++ b/lua/inline-diff/init.lua @@ -40,10 +40,12 @@ end M.config = { debounce_ms = 150, + word_del_strikethrough = true, } function M.setup(opts) M.config = vim.tbl_deep_extend("force", M.config, opts or {}) + highlight.word_del_strikethrough = M.config.word_del_strikethrough highlight.define() highlight.setup_autocmd() end @@ -225,6 +227,7 @@ function M.enable(bufnr, ref) s.ref = ref -- Ensure highlights are defined + highlight.word_del_strikethrough = M.config.word_del_strikethrough highlight.define() -- Initial refresh diff --git a/tests/highlight_spec.lua b/tests/highlight_spec.lua index d508805..84a3f09 100644 --- a/tests/highlight_spec.lua +++ b/tests/highlight_spec.lua @@ -94,3 +94,21 @@ describe("_boost_color", function() assert.is_true(math.abs((l_out - l_in) - 0.22) < 0.02, "lightness delta should be ~0.22") end) end) + +describe("define / word_del_strikethrough", function() + local function word_del_attrs() + return vim.api.nvim_get_hl(0, { name = "InlineDiffWordDel", link = false }) + end + + it("defaults to strikethrough", function() + highlight.word_del_strikethrough = nil + highlight.define() + assert.is_true(word_del_attrs().strikethrough, "strikethrough should default to true") + end) + + it("honors word_del_strikethrough = false", function() + highlight.word_del_strikethrough = false + highlight.define() + assert.is_nil(word_del_attrs().strikethrough, "strikethrough should be absent when disabled") + end) +end)