Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion doc/inline-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
<

Expand All @@ -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*

Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion lua/inline-diff/highlight.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions lua/inline-diff/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/highlight_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)