Skip to content

Commit 32cf26b

Browse files
committed
refactor(styles): rename 'code' style to 'inline-code' and update related rendering logic for improved clarity and visual distinction in text rendering
1 parent 464a555 commit 32cf26b

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/dao/browser/ui/webui/resources/agent/dao_share_image.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const TEXT_VERY_MUTED = 'rgba(30, 20, 40, 0.4)';
5858
const ACCENT_COLOR = 'rgb(70, 120, 190)';
5959
const FOOTER_BG = 'rgb(54, 59, 64)';
6060
const FOOTER_FG = 'rgb(255, 255, 255)';
61-
const CODE_BG = 'rgba(0, 0, 0, 0.06)';
61+
const INLINE_CODE_COLOR = 'rgba(30, 20, 40, 0.72)';
6262
const CODE_BLOCK_BG = 'rgba(0, 0, 0, 0.05)';
6363
const CODE_BLOCK_BORDER = 'rgba(0, 0, 0, 0.08)';
6464
const HR_COLOR = 'rgba(0, 0, 0, 0.12)';
@@ -73,8 +73,8 @@ const SYN_COMMENT = 'rgba(30, 20, 40, 0.45)';
7373
const SYN_NUMBER = 'rgb(180, 100, 30)';
7474
const SYN_FUNCTION = 'rgb(70, 100, 180)';
7575

76-
type RunStyle = 'normal' | 'bold' | 'italic' | 'bold-italic' | 'code' | 'link'
77-
| 'strike';
76+
type RunStyle = 'normal' | 'bold' | 'italic' | 'bold-italic' | 'code'
77+
| 'inline-code' | 'link' | 'strike';
7878
interface TextRun {
7979
text: string;
8080
style: RunStyle;
@@ -141,7 +141,7 @@ function tokensToRuns(
141141
out.push(...tokensToRuns(tk.tokens, 'strike'));
142142
break;
143143
case 'codespan':
144-
out.push({text: decodeEntities(tk.text || ''), style: 'code'});
144+
out.push({text: decodeEntities(tk.text || ''), style: 'inline-code'});
145145
break;
146146
case 'link':
147147
if (tk.tokens && tk.tokens.length > 0) {
@@ -175,6 +175,7 @@ function tokensToRuns(
175175

176176
function mergeStyle(a: RunStyle, b: RunStyle): RunStyle {
177177
if (a === 'code' || b === 'code') return 'code';
178+
if (a === 'inline-code' || b === 'inline-code') return 'inline-code';
178179
if (a === 'link' || b === 'link') return 'link';
179180
const isBold = a === 'bold' || a === 'bold-italic' || b === 'bold' ||
180181
b === 'bold-italic';
@@ -206,6 +207,7 @@ function fontFor(style: RunStyle, sizePx: number, weight?: number): string {
206207
case 'bold-italic':
207208
return `italic ${weight ?? 600} ${sizePx}px ${FONT_FAMILY}`;
208209
case 'code':
210+
case 'inline-code':
209211
return `${sizePx - 2}px ${MONO_FAMILY}`;
210212
case 'strike':
211213
case 'link':
@@ -278,11 +280,17 @@ function paintLine(
278280
for (const run of line.runs) {
279281
g.font = fontFor(run.style, sizePx, weight);
280282
const w = g.measureText(run.text).width;
281-
if (run.style === 'code') {
282-
g.fillStyle = CODE_BG;
283-
paintRoundedRect(g, cursorX - 2, y - sizePx + 2, w + 4, sizePx + 2, 4);
284-
}
285-
g.fillStyle = run.color || (run.style === 'link' ? ACCENT_COLOR : color);
283+
// Inline code: the prior CODE_BG pill visually read as a text-selection
284+
// highlight against the light surface. Distinguish code via the
285+
// monospace font + a muted tint instead. White-on-blue bubbles keep
286+
// their bubble text color so code stays legible on accent. Code blocks
287+
// (style 'code', set by syntaxRuns) keep their syntax-tinted palette.
288+
g.fillStyle = run.color ||
289+
(run.style === 'link' ?
290+
ACCENT_COLOR :
291+
(run.style === 'inline-code' && color === TEXT_COLOR ?
292+
INLINE_CODE_COLOR :
293+
color));
286294
g.textBaseline = 'alphabetic';
287295
g.fillText(run.text, cursorX, y);
288296
if (run.style === 'strike') {

0 commit comments

Comments
 (0)