From f9f3816e07e97c6c83218f355c868a047b1d7202 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:15:34 +0000 Subject: [PATCH 1/2] fix(web): diff columns size to the code, and long lines scroll instead of wrapping The spanning hunk row made table-layout: fixed split the table into four equal columns. A colgroup keeps line numbers narrow; the table is as wide as its longest line and the file card scrolls sideways. Co-Authored-By: Claude Opus 5.5 --- web/public/drawer.js | 5 +++++ web/public/style.css | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/web/public/drawer.js b/web/public/drawer.js index 34edbe5..f2b81cf 100644 --- a/web/public/drawer.js +++ b/web/public/drawer.js @@ -461,6 +461,11 @@ function fileCard(f, startOpen) { /** @param {import('./diffparse.js').DiffFile} f */ function splitTable(f) { const table = h('table', 'diff-split'); + // Explicit columns: narrow line numbers and code as wide as its longest line. Without them the spanning hunk row + // would set four equal columns. + const cols = h('colgroup'); + cols.append(h('col', 'diff-col-n'), h('col', 'diff-col-code'), h('col', 'diff-col-n'), h('col', 'diff-col-code')); + table.append(cols); const tbody = h('tbody'); for (const hk of f.hunks) { const sep = h('tr', 'diff-hunk-row'); diff --git a/web/public/style.css b/web/public/style.css index 1346a7c..a6bf7c7 100644 --- a/web/public/style.css +++ b/web/public/style.css @@ -1022,10 +1022,12 @@ button.danger { margin: 6px 8px; } +/* As wide as the longest line, at least the card: lines keep their layout and the card scrolls sideways. */ .diff-split { - width: 100%; + width: max-content; + min-width: 100%; border-collapse: collapse; - table-layout: fixed; + table-layout: auto; font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.45; @@ -1036,16 +1038,19 @@ button.danger { vertical-align: top; } +.diff-col-n { + width: 1%; +} + .diff-n { - width: 3.5em; + white-space: nowrap; color: var(--muted); text-align: right; user-select: none; } .diff-code { - white-space: pre-wrap; - overflow-wrap: anywhere; + white-space: pre; } .diff-code.diff-left { @@ -1078,6 +1083,7 @@ button.danger { padding: 2px 8px; background: rgb(59 130 246 / 12%); color: var(--accent); + white-space: pre; } /* "Full width" on the Diff tab: wider than any dragged width, leaving the graph its minimum. */ From b85e4f35c2603fb38b06e9955f1763113928e696 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:20:24 +0000 Subject: [PATCH 2/2] fix(web): equal diff halves with one sticky sideways scroll bar per file Long lines clip instead of pushing the new side off screen. Each file's bar sticks to the bottom of the visible diff and shifts both sides together; a sideways swipe or shift+wheel scrolls it too. Co-Authored-By: Claude Opus 5.5 --- tests/unit/web-public.test.ts | 16 ++++++++- web/public/diffparse.js | 22 +++++++++++++ web/public/drawer.js | 61 ++++++++++++++++++++++++++++++++--- web/public/style.css | 35 ++++++++++++++++---- 4 files changed, 123 insertions(+), 11 deletions(-) diff --git a/tests/unit/web-public.test.ts b/tests/unit/web-public.test.ts index b782814..04e447e 100644 --- a/tests/unit/web-public.test.ts +++ b/tests/unit/web-public.test.ts @@ -10,7 +10,7 @@ import { progressFields, } from '../../web/public/facts.js'; import { diffGraph } from '../../web/public/diff.js'; -import { openCards, parsePatch, unquotePath, wordParts } from '../../web/public/diffparse.js'; +import { longestLine, openCards, parsePatch, unquotePath, wordParts } from '../../web/public/diffparse.js'; import { commitOf, githubCommitUrl } from '../../web/public/commits.js'; import { clampDrawerWidth, DRAWER_MIN, GRAPH_MIN, parseStoredWidth } from '../../web/public/resize.js'; import { formatTokens, inputTotal, runsFor, stripText, totalTitle } from '../../web/public/usage.js'; @@ -1046,3 +1046,17 @@ Deno.test('openCards opens files until a total row budget, and never one over th assertEquals(many.filter(Boolean).length, 10); assertEquals(many.slice(0, 10).every(Boolean), true); }); + +Deno.test('longestLine counts the widest cell in columns, a tab to the next multiple of four', () => { + const file = parsePatch( + ['diff --git a/x b/x', '--- a/x', '+++ b/x', '@@ -1,2 +1,2 @@', ' short', '-\tab', '+a much longer line'].join( + '\n', + ), + ) + .files[0]; + assertEquals(longestLine(file), 'a much longer line'.length); + const tabs = + parsePatch(['diff --git a/x b/x', '--- a/x', '+++ b/x', '@@ -1 +1 @@', '-ab\tc', '+x'].join('\n')).files[0]; + assertEquals(longestLine(tabs), 5); // "ab" then a tab to column 4, then "c" + assertEquals(longestLine({ hunks: [] } as never), 0); +}); diff --git a/web/public/diffparse.js b/web/public/diffparse.js index 9333491..0a058cd 100644 --- a/web/public/diffparse.js +++ b/web/public/diffparse.js @@ -246,3 +246,25 @@ export function parsePatch(text, truncated = false) { while (headLines.length && headLines[headLines.length - 1] === '') headLines.pop(); return { head: headLines.join('\n'), files }; } + +/** Columns a tab advances to: the next multiple of this. The view sets the same `tab-size`. */ +export const TAB_SIZE = 4; + +/** + * The widest line of a file in columns, tabs expanded, so the view knows how far a side can scroll. + * @param {DiffFile} f + */ +export function longestLine(f) { + let widest = 0; + for (const hk of f.hunks) { + for (const r of hk.rows) { + for (const c of [r.left, r.right]) { + if (!c) continue; + let col = 0; + for (const ch of c.text) col = ch === '\t' ? col + TAB_SIZE - (col % TAB_SIZE) : col + 1; + if (col > widest) widest = col; + } + } + } + return widest; +} diff --git a/web/public/drawer.js b/web/public/drawer.js index f2b81cf..c970a74 100644 --- a/web/public/drawer.js +++ b/web/public/drawer.js @@ -7,7 +7,7 @@ import { writeSection } from './forms.js'; import { createLogView } from './logview.js'; import { kindOf, shortName, verdictOf, workerLabel } from './names.js'; import { commitOf, githubCommitUrl } from './commits.js'; -import { openCards, parsePatch } from './diffparse.js'; +import { longestLine, openCards, parsePatch } from './diffparse.js'; import { clampDrawerWidth, DRAWER_MIN, KEY_STEP, parseStoredWidth, WIDTH_KEY } from './resize.js'; import { formatTokens, inputTotal, runsFor } from './usage.js'; @@ -442,7 +442,7 @@ function fileCard(f, startOpen) { if (body.childElementCount) return; if (f.status === 'binary') body.append(h('p', 'note', 'Binary file: not shown.')); else if (f.hunks.length === 0) body.append(h('p', 'note', 'No line changes.')); - else body.append(splitTable(f)); + else body.append(splitTable(f), sideScroll(card, body, f)); if (f.incomplete) body.append(h('p', 'drawer-message error', 'This file is cut short.')); }; if (open) fill(); @@ -483,6 +483,56 @@ function splitTable(f) { return table; } +/** Width of one character in the diff's monospace font, measured once. */ +let charPx = 0; + +/** @param {HTMLElement} inside a code cell, so the measure uses its font */ +function charWidth(inside) { + if (charPx) return charPx; + const probe = h('span', 'diff-text', '0'.repeat(100)); + probe.style.visibility = 'hidden'; + inside.append(probe); + charPx = probe.getBoundingClientRect().width / 100 || 7; + probe.remove(); + return charPx; +} + +/** + * One sideways scroll bar per file, stuck to the bottom of the visible diff while the file is on screen. Both sides + * keep half the width; the bar shifts every line of the file together, so old and new stay aligned. A sideways + * swipe, or shift with the wheel, over the file scrolls it too. + * @param {HTMLElement} card + * @param {HTMLElement} body + * @param {import('./diffparse.js').DiffFile} f + */ +function sideScroll(card, body, f) { + const bar = h('div', 'diff-hscroll'); + const inner = h('div', 'diff-hscroll-inner'); + bar.append(inner); + const widest = longestLine(f); + const measure = () => { + const code = /** @type {HTMLElement | null} */ (card.querySelector('td.diff-code')); + if (!code || !card.isConnected) return; + const pad = parseFloat(getComputedStyle(code).paddingLeft) + parseFloat(getComputedStyle(code).paddingRight); + const overflow = Math.ceil(widest * charWidth(code) + pad - code.clientWidth); + bar.hidden = overflow <= 0; + inner.style.width = `${card.clientWidth + Math.max(0, overflow)}px`; + if (overflow <= 0) bar.scrollLeft = 0; + card.style.setProperty('--diff-x', `${bar.scrollLeft}px`); + }; + bar.addEventListener('scroll', () => card.style.setProperty('--diff-x', `${bar.scrollLeft}px`)); + body.addEventListener('wheel', (e) => { + const sideways = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.shiftKey ? e.deltaY : 0; + if (!sideways || bar.hidden) return; + bar.scrollLeft += sideways; + e.preventDefault(); + }, { passive: false }); + const watch = new ResizeObserver(() => (card.isConnected ? measure() : watch.disconnect())); + watch.observe(card); + requestAnimationFrame(measure); + return bar; +} + /** * A side's line number and text cells; an empty side is a blank pair. * @param {import('./diffparse.js').Cell | null} c @@ -492,9 +542,12 @@ function cells(c, side) { if (!c) return [h('td', `diff-n diff-empty diff-${side}`), h('td', `diff-code diff-empty diff-${side}`)]; const kind = c.kind === 'context' ? '' : ` diff-${c.kind}`; const code = h('td', `diff-code diff-${side}${kind}`); + // The text sits in a span that the file's scroll bar shifts sideways; the cell clips it. + const text = h('span', 'diff-text'); if (c.parts) { - code.append(...c.parts.map((p) => h('span', p.changed ? 'diff-word' : '', p.text))); - } else code.textContent = c.text; + text.append(...c.parts.map((p) => h('span', p.changed ? 'diff-word' : '', p.text))); + } else text.textContent = c.text; + code.append(text); return [h('td', `diff-n diff-${side}${kind}`, String(c.n)), code]; } diff --git a/web/public/style.css b/web/public/style.css index a6bf7c7..b6d8336 100644 --- a/web/public/style.css +++ b/web/public/style.css @@ -1014,7 +1014,7 @@ button.danger { } .diff-card-body { - overflow-x: auto; + overflow: visible; } .diff-card-body > .note, @@ -1022,12 +1022,11 @@ button.danger { margin: 6px 8px; } -/* As wide as the longest line, at least the card: lines keep their layout and the card scrolls sideways. */ +/* Two equal halves: a long line is clipped, and the file's scroll bar shifts both sides together. */ .diff-split { - width: max-content; - min-width: 100%; + width: 100%; border-collapse: collapse; - table-layout: auto; + table-layout: fixed; font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.45; @@ -1039,7 +1038,7 @@ button.danger { } .diff-col-n { - width: 1%; + width: 7ch; } .diff-n { @@ -1050,7 +1049,29 @@ button.danger { } .diff-code { + overflow: hidden; white-space: pre; + tab-size: 4; +} + +.diff-text { + display: inline-block; + transform: translateX(calc(-1 * var(--diff-x, 0px))); +} + +/* Sticks to the bottom of the visible diff while its file is on screen. */ +.diff-hscroll { + position: sticky; + bottom: 0; + z-index: 1; + overflow-x: auto; + overflow-y: hidden; + border-top: 1px solid var(--line); + background: var(--panel); +} + +.diff-hscroll-inner { + height: 1px; } .diff-code.diff-left { @@ -1084,6 +1105,8 @@ button.danger { background: rgb(59 130 246 / 12%); color: var(--accent); white-space: pre; + overflow: hidden; + text-overflow: ellipsis; } /* "Full width" on the Diff tab: wider than any dragged width, leaving the graph its minimum. */