Skip to content

Commit 9207f82

Browse files
committed
Polish connector glyph rendering
1 parent a39de43 commit 9207f82

4 files changed

Lines changed: 18 additions & 74 deletions

File tree

lua/diffbandit/config.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ local defaults = {
4242
},
4343
highlights = {},
4444
},
45-
connectors = {
46-
context = " ",
47-
change = {
48-
single = "──",
49-
start = "╭─",
50-
mid = "",
51-
finish = "╰─",
52-
},
53-
},
5445
},
5546
navigation = {
5647
align_on_jump = true,

lua/diffbandit/highlights.lua

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,6 @@ local function apply_diff_variants(config)
286286
sp = add_bg,
287287
})
288288

289-
apply_group("DiffBanditDeleteLeftSeparatorConnector", {
290-
fg = delete_bg,
291-
underline = true,
292-
sp = delete_bg,
293-
})
294-
295289
apply_group("DiffBanditDeleteRightSeparatorConnector", {
296290
fg = delete_bg,
297291
underline = true,
@@ -338,34 +332,34 @@ local function apply_diff_variants(config)
338332
})
339333

340334
-- Stroke colors for connector routing (use background colors for visual continuity with diff regions)
341-
apply_group("DiffBanditConnectorAddLine", { fg = add_bg })
342-
apply_group("DiffBanditConnectorDeleteLine", { fg = delete_bg })
343-
apply_group("DiffBanditConnectorChangeLine", { fg = change_bg })
335+
apply_group("DiffBanditConnectorAddLine", { fg = add_bg, bold = true })
336+
apply_group("DiffBanditConnectorDeleteLine", { fg = delete_bg, bold = true })
337+
apply_group("DiffBanditConnectorChangeLine", { fg = change_bg, bold = true })
344338

345339
-- Expansion glyphs: foreground matches the background color for seamless visual bridging
346340
-- The ◥/◤ triangles appear with fg color matching the add/delete background, creating
347341
-- a visual connection from the underline to the colored background region
348342
apply_group("DiffBanditConnectorExpansionAdd", {
349343
fg = add_bg,
350344
bg = normal_bg,
345+
bold = true,
351346
})
352347
apply_group("DiffBanditConnectorExpansionAddUnderline", {
353348
fg = add_bg,
354349
bg = normal_bg,
355350
underline = true,
356351
sp = add_bg,
352+
bold = true,
357353
})
358354
apply_group("DiffBanditConnectorExpansionDelete", {
359355
fg = delete_bg,
360356
bg = normal_bg,
357+
bold = true,
361358
})
362359
apply_group("DiffBanditConnectorExpansionChange", {
363360
fg = change_bg,
364361
bg = normal_bg,
365-
})
366-
apply_group("DiffBanditConnectorDeleteCutout", {
367-
fg = normal_bg,
368-
bg = delete_bg,
362+
bold = true,
369363
})
370364

371365
apply_group("DiffBanditConnectorContext", {

lua/diffbandit/view.lua

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
local M = {}
22

3-
local function pad_connector(str, width)
4-
local display = vim.fn.strdisplaywidth(str)
5-
if display >= width then
6-
return str
7-
end
8-
return str .. string.rep(" ", width - display)
9-
end
10-
11-
local function connector_for(chunk_type, position, total, cfg, width)
12-
local shapes = cfg[chunk_type] or cfg.change
13-
if not shapes then
14-
return pad_connector(cfg.context or "", width)
15-
end
16-
17-
local key
18-
if total <= 1 then
19-
key = "single"
20-
elseif position == 1 then
21-
key = "start"
22-
elseif position == total then
23-
key = "finish"
24-
else
25-
key = "mid"
26-
end
27-
28-
local value = shapes[key] or cfg.context or ""
29-
return pad_connector(value, width)
30-
end
31-
323
function M.build(left_lines, right_lines, hunks, config)
334
local connector_width = config.ui.connector_width or 3
34-
local connectors_cfg = config.ui.connectors or {}
5+
local blank_connector = string.rep(" ", connector_width)
356

367
local left_view, right_view, connector_view, line_meta = {}, {}, {}, {}
378
local chunks = {}
389

3910
local prev_a_end = 0
4011
local prev_b_end = 0
4112

42-
local function add_line(left_text, right_text, connector_text, meta)
13+
local function add_line(left_text, right_text, meta)
4314
-- Only add actual content lines to each buffer
4415
-- Filler rows exist only in connector view for alignment
4516
local left_index = nil
@@ -58,7 +29,7 @@ function M.build(left_lines, right_lines, hunks, config)
5829
end
5930

6031
-- Connector always has full aligned view
61-
connector_view[#connector_view + 1] = pad_connector(connector_text or connectors_cfg.context or "", connector_width)
32+
connector_view[#connector_view + 1] = blank_connector
6233
line_meta[#line_meta + 1] = meta
6334

6435
meta.left_index = left_index
@@ -101,7 +72,7 @@ function M.build(left_lines, right_lines, hunks, config)
10172
b_idx = b_idx + 1
10273
end
10374

104-
add_line(left_text, right_text, connectors_cfg.context or "", {
75+
add_line(left_text, right_text, {
10576
kind = "context",
10677
chunk = nil,
10778
left_line = left_line_num,
@@ -170,25 +141,9 @@ function M.build(left_lines, right_lines, hunks, config)
170141
end
171142
end
172143

173-
-- Connector text is driven by per-row kind, not hunk type.
174-
-- Add/delete rows (including those produced inside change hunks) are rendered
175-
-- via session.lua path rendering (triangles/bars/underlines).
176-
local connector_text
177-
if kind == "add" or kind == "delete" then
178-
connector_text = string.rep(" ", connector_width)
179-
elseif kind == "change" then
180-
local change_total = math.min(h.left.count, h.right.count)
181-
if change_total <= 0 then
182-
change_total = 1
183-
end
184-
connector_text = connector_for("change", math.min(i, change_total), change_total, connectors_cfg, connector_width)
185-
else
186-
connector_text = connectors_cfg.context or ""
187-
end
188-
189144
-- Keep change classification at the line level; intra-line coloring decides blue/green mix.
190-
191-
add_line(left_text, right_text, connector_text, {
145+
-- Connector glyphs are rendered from route paths in session.lua.
146+
add_line(left_text, right_text, {
192147
kind = kind,
193148
chunk = h.index,
194149
left_line = left_line_num,
@@ -258,7 +213,7 @@ function M.build(left_lines, right_lines, hunks, config)
258213
b_idx = b_idx + 1
259214
end
260215

261-
add_line(left_text, right_text, connectors_cfg.context or "", {
216+
add_line(left_text, right_text, {
262217
kind = "context",
263218
chunk = nil,
264219
left_line = left_line_num,

tests/run.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,8 @@ do
16381638
"Add override should propagate to overview add markers")
16391639
assert_eq(get_hl("DiffBanditConnectorAddLine").fg, 0x112233,
16401640
"Add override should propagate to add connector rails")
1641+
assert_eq(get_hl("DiffBanditConnectorAddLine").bold, true,
1642+
"Connector rail glyphs should render bold by default")
16411643
assert_eq(get_hl("DiffBanditDelete").bg, 0x445566,
16421644
"Delete override should accept hex strings")
16431645
assert_eq(get_hl("DiffBanditOverviewDelete").bg, 0x445566,
@@ -1650,6 +1652,8 @@ do
16501652
"Change override should propagate to overview change markers")
16511653
assert_eq(get_hl("DiffBanditConnectorExpansionChange").fg, 0x778899,
16521654
"Change override should propagate to change wedges")
1655+
assert_eq(get_hl("DiffBanditConnectorExpansionChange").bold, true,
1656+
"Connector transition glyphs should render bold by default")
16531657
assert_eq(get_hl("DiffBanditChangeEmphasis").bg, 0xABCDEF,
16541658
"Change emphasis override should win over adaptive derivation")
16551659

0 commit comments

Comments
 (0)