Skip to content

Commit b3a763f

Browse files
committed
feat(hl): Add plugin local groups for all the diff highlights
Adds new highlight groups shadowing all the default diff highlights: - `DiffviewDiffAdd` -> `DiffAdd` - `DiffviewDiffDelete` -> `DiffDelete` - `DiffviewDiffChange` -> `DiffChange` - `DiffviewDiffText` -> `DiffText` These are set as 'winhl' in all the diff buffers created by the plugin. This way users will be able to change the diff highlighting for Diffview only, without affecting the use of these groups outside of the plugin. OTHER CHANGES: Having `enhanced_diff_hl` enabled will now highlight delete fill-chars more subtly in *all* layouts. Not only `diff2*` layouts. (fixes sindrets#340)
1 parent ea5a749 commit b3a763f

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

doc/diffview.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,23 @@ EXAMPLE CONFIGURATION WITH DEFAULT SETTINGS: |diffview.defaults|
359359
enhanced_diff_hl *diffview-config-enhanced_diff_hl*
360360
Type: `boolean`, Default: `false`
361361

362-
Enable/disable enhanced diff highlighting. In `diff2*` layouts this
363-
will highlight the delete fill-chars more subtly, and show
364-
|hl-DiffAdd| in the old state buffer, as |hl-DiffDelete|. This makes
365-
the highlighting more inline with how 2-way diffs are displayed in
366-
other diff tools. As - in a 2-way diff - an "addition" in the old
367-
state actually represents a deletion.
362+
Enable/disable enhanced diff highlighting. This option has slightly
363+
different effects in different |diffview-layouts|.
364+
365+
In all layouts: highlight delete fill-chars more subtly. These chars
366+
are used as filler in places where other diff buffers have
367+
insertions at that postion. Unfortunately many color schemes give
368+
it a distracting highlight, such as a bright red. This makes diffs
369+
more difficult to visually parse, as your eyes get drawn towards
370+
the bright red areas of your display with absolutely no
371+
information in them.
372+
373+
In `diff2*` layouts: show |hl-DiffAdd| as |hl-DiffDelete| in the
374+
buffer representing the old state. This makes the highlighting
375+
more inline with how 2-way diffs are displayed in other diff
376+
tools. As - in a 2-way diff - an "insertion" in the old state
377+
actually represents a deletion from the perspective of the new
378+
state.
368379

369380
git_cmd *diffview-config-git_cmd*
370381
Type: `string[]`, Default: `{ "git" }`
@@ -419,6 +430,7 @@ view.x.layout *diffview-config-view.x.layout*
419430
• C: THEIRS (incoming branch)
420431
• D: BASE (common ancestor)
421432

433+
*diffview-layouts*
422434
{diff1_plain}
423435
Available for: merge_tool
424436

@@ -904,7 +916,7 @@ conflict_choose({version}) *diffview-actions-conflict_choos
904916
See |diffview-conflict-versions| to tell what versions of the
905917
file these names correspond with.
906918

907-
conflict_choose_all({version}) *diffview-actions-conflict_choose_all*
919+
conflict_choose_all({version}) *diffview-actions-conflict_choose_all*
908920
Contexts: `merge_tool`, `file_panel`
909921

910922
Replace all merge conflicts in the current file at once. Choosing `'none'`

lua/diffview/hl.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ M.hl_links = {
460460
StatusDeleted = "diffRemoved",
461461
StatusBroken = "diffRemoved",
462462
StatusIgnored = "Comment",
463+
DiffAdd = "DiffAdd",
464+
DiffDelete = "DiffDelete",
465+
DiffChange = "DiffChange",
466+
DiffText = "DiffText",
463467
}
464468

465469
function M.update_diff_hl()
@@ -468,12 +472,14 @@ function M.update_diff_hl()
468472
local style = M.get_style("DiffDelete", true) or "NONE"
469473

470474
M.hi("DiffviewDiffAddAsDelete", { fg = fg, bg = bg, style = style })
471-
M.hi_link("DiffviewDiffDelete", "Comment", { default = true })
475+
M.hi_link("DiffviewDiffDeleteDim", "Comment", { default = true })
476+
477+
if config.get_config().enhanced_diff_hl then
478+
M.hi_link("DiffviewDiffDelete", "DiffviewDiffDeleteDim")
479+
end
472480
end
473481

474482
function M.setup()
475-
M.update_diff_hl()
476-
477483
for name, v in pairs(M.get_hl_groups()) do
478484
v = vim.tbl_extend("force", v, { default = true })
479485
M.hi("Diffview" .. name, v)
@@ -482,6 +488,8 @@ function M.setup()
482488
for from, to in pairs(M.hl_links) do
483489
M.hi_link("Diffview" .. from, to, { default = true })
484490
end
491+
492+
M.update_diff_hl()
485493
end
486494

487495
return M

lua/diffview/scene/views/standard/standard_view.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,15 @@ function StandardView:post_layout()
7878
if config.get_config().enhanced_diff_hl then
7979
self.winopts.diff2.a.winhl = {
8080
"DiffAdd:DiffviewDiffAddAsDelete",
81-
"DiffDelete:DiffviewDiffDelete",
81+
"DiffDelete:DiffviewDiffDeleteDim",
82+
"DiffChange:DiffviewDiffChange",
83+
"DiffText:DiffviewDiffText",
8284
}
8385
self.winopts.diff2.b.winhl = {
84-
"DiffDelete:DiffviewDiffDelete",
86+
"DiffDelete:DiffviewDiffDeleteDim",
87+
"DiffAdd:DiffviewDiffAdd",
88+
"DiffChange:DiffviewDiffChange",
89+
"DiffText:DiffviewDiffText",
8590
}
8691
end
8792

lua/diffview/vcs/file.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ function File:init(opt)
8787
foldcolumn = "1",
8888
foldlevel = 0,
8989
foldenable = true,
90+
winhl = {
91+
"DiffAdd:DiffviewDiffAdd",
92+
"DiffDelete:DiffviewDiffDelete",
93+
"DiffChange:DiffviewDiffChange",
94+
"DiffText:DiffviewDiffText",
95+
},
9096
}
9197

9298
-- Set winbar info

0 commit comments

Comments
 (0)