diff --git a/e2e/rules-templates.spec.ts b/e2e/rules-templates.spec.ts index 34d36c99..d2bd26fd 100644 --- a/e2e/rules-templates.spec.ts +++ b/e2e/rules-templates.spec.ts @@ -94,6 +94,10 @@ test('a template replaces the routing of the one file that holds it', async ({pa await expect(diff.locator('[data-kind="add"]', {hasText: 'dip(geoip:cn) -> direct'})).toHaveCount(1); await expect(diff.locator('[data-kind="del"]', {hasText: 'domain(geosite: telegram) -> proxy'})).toHaveCount(1); await expect(diff).not.toContainText('tproxy_port'); + // At phone width a long line wraps inside the panel rather than scrolling it sideways. + await page.setViewportSize({width: 320, height: 800}); + await expect.poll(() => diff.evaluate(el => el.scrollWidth - el.clientWidth)).toBe(0); + await page.setViewportSize({width: 1440, height: 1000}); await dialog.getByRole('button', {name: 'Apply', exact: true}).click(); await expect(page.locator('.rp-toast.positive')).toContainText('Applied Bypass mainland China to config.dae'); await expect(dialog).toHaveCount(0); diff --git a/src/ui/Diff.tsx b/src/ui/Diff.tsx index 0aa97e93..b2e35104 100644 --- a/src/ui/Diff.tsx +++ b/src/ui/Diff.tsx @@ -1,7 +1,8 @@ import {cx} from './cx'; // A line diff as a unified listing: removed lines marked `-`, added `+`, and each gap of unchanged lines as `gap`, the -// caller's text for it. The marks are also read out, since colour alone does not say which side a line is on. +// caller's text for it. The marks are also read out, since colour alone does not say which side a line is on. A long +// line wraps under its text, not under the mark; the newline stays in the text so a copy keeps one line per row. export type DiffRow = {kind: 'same' | 'add' | 'del'; text: string} | {kind: 'gap'; text: string}; const marks = {same: ' ', add: '+', del: '-', gap: ' '} as const; export function Diff({rows, label}: {rows: DiffRow[]; label: string}) { @@ -9,10 +10,12 @@ export function Diff({rows, label}: {rows: DiffRow[]; label: string}) { // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- The bounded listing needs keyboard focus to scroll.
       {rows.map((row, index) => (
-        
+        
           {marks[row.kind]}
-          {row.text}
-          {'\n'}
+          
+            {row.text}
+            {'\n'}
+          
         
       ))}
     
diff --git a/src/ui/code/CodeEditor.tsx b/src/ui/code/CodeEditor.tsx index f0fd5cce..3dd06eb1 100644 --- a/src/ui/code/CodeEditor.tsx +++ b/src/ui/code/CodeEditor.tsx @@ -104,7 +104,8 @@ const theme = EditorView.theme({ '.cm-tooltip': {backgroundColor: 'var(--rp-surface)', border: '1px solid var(--rp-hl-high)', borderRadius: 'var(--rp-r-md)', color: 'var(--rp-text)'}, '.cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]': {backgroundColor: 'var(--rp-selected)', color: 'var(--rp-text)'}, '.cm-tooltip.cm-tooltip-autocomplete > ul': { - fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', monospace" + fontFamily: "ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', monospace", + fontVariantLigatures: 'none' }, '.cm-panels': {backgroundColor: 'var(--rp-surface)', color: 'var(--rp-text)'}, '.cm-panels-bottom': {borderTop: '1px solid var(--rp-hl-med)'}, diff --git a/src/ui/styles/page-layout.css b/src/ui/styles/page-layout.css index ee9dffd9..846262bf 100644 --- a/src/ui/styles/page-layout.css +++ b/src/ui/styles/page-layout.css @@ -87,9 +87,11 @@ --rp-code-punctuation: var(--rp-subtle); --rp-code-operator: var(--rp-subtle); } +/* Code shows what was typed: a programming font's ligatures would draw `->` or `!=` as one glyph. */ .rp-code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', monospace; font-size: var(--rp-text-sm); + font-variant-ligatures: none; } /* Right to left, technical values keep their own order. A table cell or a detail value takes its direction from its text, so a domain, address or path reads left to right while a name in the page's script does not; code, rule text diff --git a/src/ui/styles/routing.css b/src/ui/styles/routing.css index 0e614f58..c0893c8c 100644 --- a/src/ui/styles/routing.css +++ b/src/ui/styles/routing.css @@ -109,6 +109,7 @@ .rp-tree-tile[data-stage='rule'] .l { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono', monospace; font-size: var(--rp-text-xs); + font-variant-ligatures: none; } .rp-tree-tile .s { margin-inline-start: 8px; diff --git a/src/ui/styles/tables-forms.css b/src/ui/styles/tables-forms.css index b3eb853b..542a14bf 100644 --- a/src/ui/styles/tables-forms.css +++ b/src/ui/styles/tables-forms.css @@ -315,8 +315,12 @@ .rp-kv.row .k { line-height: 20px; } -/* A unified line diff (Diff.tsx) in the code face: added and removed lines take a quiet highlight and their mark the - positive or negative text colour; a gap between hunks is a label. */ +/* A unified line diff (Diff.tsx) in the code face: added and removed lines take a faint positive or negative tint and + their mark the matching text colour; a gap between hunks is a label. The tint is see-through, so a tinted row still + reads as part of the panel in every palette (an opaque highlight can match the dialog behind the panel instead). Each row is a mark column and a text column on the + one panel, so a highlight runs from edge to edge and a long line wraps under its text instead of scrolling sideways. + The mark hangs in the row's start padding rather than sitting in a grid cell: a grid item is a block, and a copy + would put the mark and its text on separate lines. */ .rp-diff { max-height: 320px; margin: 0; @@ -327,15 +331,23 @@ } .rp-diff-line { display: block; - padding-inline: 8px; - white-space: pre; + padding-inline: calc(8px + 2ch) 8px; + text-indent: -2ch; + white-space: pre-wrap; } -.rp-diff-line:is([data-kind='add'], [data-kind='del']) { - background: var(--rp-hl-low); +.rp-diff-line[data-kind='add'] { + background: color-mix(in srgb, var(--rp-positive) 12%, transparent); +} +.rp-diff-line[data-kind='del'] { + background: color-mix(in srgb, var(--rp-negative) 12%, transparent); } .rp-diff-mark { display: inline-block; width: 2ch; + text-indent: 0; +} +.rp-diff-text { + overflow-wrap: anywhere; } .rp-diff-line[data-kind='add'] .rp-diff-mark { color: var(--rp-positive-text);