diff --git a/src/web/public/styles.css b/src/web/public/styles.css index d5a1957d..ffabfddb 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -14126,9 +14126,20 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat overflow-wrap: break-word; } -/* A linked path keeps `word-break: break-all` (the a.rv-path rule below), which lets its - column shrink the same way. A floor keeps about ten characters of the path per line. */ -.rv-table-wrap td:has(a.rv-path:not(.rv-path-link)) { +/* Inline code and links hold long tokens such as URLs, identifiers and hashes. Chromium + finds no break point inside one, since it never breaks after `/`. Under `break-word` + the longest token set its column's width and the whole table scrolled sideways, so + these tokens break anywhere. A linked path already does, through the `break-all` of + the a.rv-path rule above. CSS cannot tell an autolink from a link with a prose label, + so a label breaks anywhere too. The one exception is a path link's label + (.rv-path-link), which keeps breaking between words. */ +.rv-table-wrap td :is(code, a:not(.rv-path-link)) { + overflow-wrap: anywhere; +} + +/* Breaking anywhere lets a column shrink to one letter per line, so a cell holding such + a token gets a floor of about ten characters. */ +.rv-table-wrap td:has(code, a:not(.rv-path-link)) { min-width: 6em; } diff --git a/test/response-viewer-table-cells.test.ts b/test/response-viewer-table-cells.test.ts index 166a8023..f7a01798 100644 --- a/test/response-viewer-table-cells.test.ts +++ b/test/response-viewer-table-cells.test.ts @@ -8,12 +8,16 @@ * whose headers filled the width, the column under an empty header shrank to one letter per * line. Cells now use `break-word`, so a column is never narrower than its longest word. * - * A linkified path (`a.rv-path`) keeps `word-break: break-all`, which has the same effect on - * its column, so a cell that holds one gets a minimum width. + * Under `break-word`, a token with no break point sets its column's width. Chromium never + * breaks after `/`, so a URL, an identifier or a hash in backticks made the whole table + * scroll sideways on a phone. Inline code and links in a cell therefore break anywhere, + * like a linkified path (`a.rv-path`, `word-break: break-all`) always did. That lets their + * column shrink the same way, so a cell holding one gets a minimum width. * * jsdom has no layout, so this pins the declarations. Firefox and Chromium were measured - * when the change was made, on a 390 px view: the label column went from one letter per - * line to whole words, a path column from 48 px to 83 px, and a `#` column kept its 32 px. + * when the change was made, in a 360 px column: URL, identifier and hash tables fit as they + * did on master, a path column went from 48 px to 80 px, and a `-v` column from 52 px to + * 80 px. */ import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; @@ -22,12 +26,29 @@ import { describe, expect, it } from 'vitest'; const publicCss = (name: string) => readFileSync(resolve(import.meta.dirname, '../src/web/public', name), 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''); +/** The selectors of a rule, split on the commas outside `:is()`, `:has()` and `:not()`. */ +function selectorList(prelude: string): string[] { + const parts: string[] = []; + let depth = 0; + let start = 0; + for (let i = 0; i < prelude.length; i++) { + if (prelude[i] === '(') depth++; + else if (prelude[i] === ')') depth--; + else if (prelude[i] === ',' && depth === 0) { + parts.push(prelude.slice(start, i).trim()); + start = i + 1; + } + } + parts.push(prelude.slice(start).trim()); + return parts; +} + /** Every rule whose selector list contains `selector`, in cascade order across both sheets. */ function rulesFor(selector: string): string[] { const bodies: string[] = []; for (const css of [publicCss('styles.css'), publicCss('mobile.css')]) { for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { - if (match[1].split(',').some((s) => s.trim() === selector)) bodies.push(match[2]); + if (selectorList(match[1]).includes(selector)) bodies.push(match[2]); } } return bodies; @@ -57,8 +78,9 @@ describe('rendered markdown table cells', () => { } ); - it('gives a cell holding a linked path a minimum width, since the path breaks anywhere', () => { + it('breaks inline code and links in a cell anywhere, and gives their cell a minimum width', () => { expect(lastValue('.rv-text a.rv-path', 'word-break')).toBe('break-all'); - expect(lastValue('.rv-table-wrap td:has(a.rv-path:not(.rv-path-link))', 'min-width')).toBe('6em'); + expect(lastValue('.rv-table-wrap td :is(code, a:not(.rv-path-link))', 'overflow-wrap')).toBe('anywhere'); + expect(lastValue('.rv-table-wrap td:has(code, a:not(.rv-path-link))', 'min-width')).toBe('6em'); }); });