fix(ui): keep theme text and selections readable (#6226)

* fix(ui): keep theme text and selections readable

* fix(tui): theme the blank composer cursor cell

* refactor(webui): centralize diff theme colors

* fix(tui): keep conversation selections readable

* fix(ui): preserve nested syntax colors and selection lifetimes
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-15 15:21:28 +08:00
1 parent 73c2441abc
commit c24153db86
32 files changed
+451 -165

No files matched your search

@@ -179,7 +179,6 @@ function CliAppMentionToken({
isHero?: boolean;
}) {
const { t } = useTranslation();
const color = app.brand_color || INLINE_TOKEN_HIGHLIGHT_COLOR;
const displayName = app.display_name?.trim() || app.name;
const mentionName = variant === "message"
? displayName
@@ -195,7 +194,6 @@ function CliAppMentionToken({
title={t("thread.composer.mentions.cliTitle", {
name: variant === "message" ? `${displayName} (${label})` : displayName,
})}
color={color}
className={variant === "composer" ? "font-normal" : "inline-flex max-w-full items-baseline [overflow-wrap:anywhere]"}
>
<span
@@ -250,7 +248,6 @@ function McpPresetMentionToken({
isHero?: boolean;
}) {
const { t } = useTranslation();
const color = preset.brand_color || INLINE_TOKEN_HIGHLIGHT_COLOR;
const displayName = preset.display_name?.trim() || preset.name;
const mentionName = variant === "message"
? displayName
@@ -266,7 +263,6 @@ function McpPresetMentionToken({
title={t("thread.composer.mentions.mcpTitle", {
name: variant === "message" ? `${displayName} (${label})` : displayName,
})}
color={color}
className={variant === "composer" ? "font-normal" : "inline-flex max-w-full items-baseline [overflow-wrap:anywhere]"}
>
<span
+10 -29
View File
@@ -22,7 +22,6 @@ interface CodeBlockProps {
interface HighlightedCodeProps {
language?: string;
code: string;
isDark: boolean;
chrome: "default" | "none";
showLineNumbers: boolean;
wrapLongLines: boolean;
@@ -46,13 +45,9 @@ const ANSI_LANGUAGES = new Set(["ansi", "ansi-output"]);
const LazyHighlightedCode = lazy(async () => {
const [
{ default: SyntaxHighlighter },
{ default: oneDark },
{ default: oneLight },
{ ViewportCodeRows },
] = await Promise.all([
import("react-syntax-highlighter/dist/esm/prism-async-light"),
import("react-syntax-highlighter/dist/esm/styles/prism/one-dark"),
import("react-syntax-highlighter/dist/esm/styles/prism/one-light"),
import("@/components/ViewportCodeRows"),
]);
@@ -60,29 +55,16 @@ const LazyHighlightedCode = lazy(async () => {
default({
language,
code,
isDark,
chrome,
showLineNumbers,
wrapLongLines,
viewportHighlight,
}: HighlightedCodeProps) {
const theme = isDark ? oneDark : oneLight;
const transparentTheme = chrome === "none" ? {
...theme,
'pre[class*="language-"]': {
...theme['pre[class*="language-"]'],
background: "transparent",
},
'code[class*="language-"]': {
...theme['code[class*="language-"]'],
background: "transparent",
},
} : theme;
return (
<SyntaxHighlighter
language={language || "text"}
style={transparentTheme}
useInlineStyles={false}
style={{}}
customStyle={{
background: "transparent",
margin: 0,
@@ -105,7 +87,7 @@ const LazyHighlightedCode = lazy(async () => {
lineNumberStyle={{
minWidth: "2.6em",
paddingRight: "1.15rem",
color: isDark ? "rgba(212, 212, 216, 0.45)" : "rgba(63, 63, 70, 0.68)",
color: "var(--code-comment)",
fontFamily: CODE_FONT_STACK,
userSelect: "none",
}}
@@ -125,8 +107,8 @@ function renderPlainText(value: string): ReactNode {
return value;
}
function renderAnsiText(value: string): ReactNode {
return parseAnsiSegments(value).map((segment, index) => (
function renderAnsiText(value: string, theme: "light" | "dark"): ReactNode {
return parseAnsiSegments(value, theme).map((segment, index) => (
<span key={index} style={segment.style}>
{segment.text}
</span>
@@ -168,14 +150,14 @@ function CodeTextBlock({
<code className="text-inherit">
{showLineNumbers && compact ? (
<span className="flex min-w-max">
<span aria-hidden className="shrink-0 select-none pr-[1.15rem] text-right text-muted-foreground/60"
<span aria-hidden className="shrink-0 select-none pr-[1.15rem] text-right text-muted-foreground"
style={{ minWidth: "4.25em" }}>{lines.map((_, index) => index + 1).join("\n")}</span>
<span>{renderText(code)}</span>
</span>
) : showLineNumbers ? (
lines.map((line, index) => (
<span key={index} className="flex min-w-max">
<span className="w-10 shrink-0 select-none pr-4 text-right text-muted-foreground/60">
<span className="w-10 shrink-0 select-none pr-4 text-right text-muted-foreground">
{index + 1}
</span>
<span className="whitespace-pre">{renderText(line || " ")}</span>
@@ -264,7 +246,7 @@ export const CodeBlock = memo(function CodeBlock({
<div
ref={rootRef}
className={cn(
"not-prose relative",
"not-prose relative code-content",
useViewportHighlight ? "overflow-visible" : "overflow-hidden",
hasChrome && "rounded-floating bg-secondary/70",
className,
@@ -277,7 +259,7 @@ export const CodeBlock = memo(function CodeBlock({
chrome={chrome}
showLineNumbers={showLineNumbers}
testId="ansi-code"
renderText={renderAnsiText}
renderText={(value) => renderAnsiText(value, isDark ? "dark" : "light")}
compact={useViewportHighlight}
/>
) : highlight && withinHighlightBudget && (!deferHighlight || highlightedSource === code) ? (
@@ -295,7 +277,6 @@ export const CodeBlock = memo(function CodeBlock({
<LazyHighlightedCode
language={syntaxLanguage}
code={code}
isDark={isDark}
chrome={chrome}
showLineNumbers={showLineNumbers}
wrapLongLines={wrapLongLines}
@@ -317,7 +298,7 @@ export const CodeBlock = memo(function CodeBlock({
onClick={onCopy}
className={cn(
"absolute right-2.5 top-2.5 z-10 inline-flex h-8 w-8 items-center justify-center rounded-full",
"text-muted-foreground/75 transition-colors hover:text-foreground",
"text-muted-foreground transition-colors hover:text-foreground",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
)}
aria-label={copyLabel}
+1 -1
View File
@@ -108,7 +108,7 @@ export function FileReferenceChip({
>
{display === "path" && directory ? (
<>
<span className="text-muted-foreground/65">{directory}</span>
<span className="text-muted-foreground">{directory}</span>
<span className={cn("font-semibold", interactive && "text-sky-700 dark:text-sky-200")}>{name}</span>
</>
) : (
@@ -13,7 +13,7 @@ export function InlineTokenHighlight({
}: {
children: ReactNode;
className?: string;
color: string;
color?: string;
testId?: string;
title?: string;
}) {
@@ -22,7 +22,7 @@ export function InlineTokenHighlight({
data-testid={testId}
title={title}
className={cn(
"relative inline font-[550] transition-colors duration-150",
"relative inline font-[550] text-foreground transition-colors duration-150",
className,
)}
style={{ color }}
+1 -1
View File
@@ -261,7 +261,7 @@ export function MessageBlockMenuActions({
{timestampLabel || automationSourceLabel ? (
<div
data-message-block-metadata
className={cn("mt-0.5 w-full border-t border-border/45 px-1.5 pt-1 leading-4", sheet ? "px-2 text-xs text-muted-foreground" : "text-[10px] text-muted-foreground/45")}
className={cn("mt-0.5 w-full border-t border-border/45 px-1.5 pt-1 leading-4 text-muted-foreground", sheet ? "px-2 text-xs" : "text-[10px]")}
>
{timestampLabel ? (
<time
+1 -1
View File
@@ -17,7 +17,7 @@ const CodeChunk = memo(function CodeChunk({ rows, text, start, stylesheet, useIn
}) {
return (
<span data-code-chunk={start / CHUNK_LINES} className="flex min-w-max">
<span aria-hidden className="shrink-0 select-none pr-[1.15rem] text-right text-muted-foreground/60"
<span aria-hidden className="shrink-0 select-none pr-[1.15rem] text-right text-muted-foreground"
style={{ minWidth: "4.25em" }}>
{rows.map((_, index) => start + index + 1).join("\n")}
</span>
@@ -131,7 +131,7 @@ export function ComposerUsagePopover({
aria-label={triggerLabel}
className={cn(
"touch-target inline-flex size-5 shrink-0 items-center justify-center rounded-full",
"text-muted-foreground/75 transition-colors hover:text-foreground/85",
"text-muted-foreground transition-colors hover:text-foreground",
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
showLabel && "w-auto gap-1.5 px-2 text-xs",
)}
@@ -154,7 +154,7 @@ export function ComposerUsagePopover({
"size-[15px] shrink-0 -rotate-90",
status === "critical" && "text-destructive",
status === "caution" && "text-amber-600 dark:text-amber-400",
status === "normal" && "text-muted-foreground/75",
status === "normal" && "text-muted-foreground",
)}
>
<circle
@@ -38,7 +38,7 @@ export function StreamErrorNotice({ error, onDismiss }: StreamErrorNoticeProps)
/>
<div className="flex-1">
<p className="font-medium">{title}</p>
<p className="mt-0.5 text-destructive/80">{body}</p>
<p className="mt-0.5 text-destructive">{body}</p>
</div>
<Button
variant="ghost"
@@ -2645,7 +2645,7 @@ export function ThreadComposer({
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
className={cn(
inputTextClasses,
"relative z-10 block caret-foreground placeholder:text-muted-foreground/70",
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
"focus:outline-none focus-visible:outline-none",
"disabled:cursor-not-allowed",
hasMentionDecorations && "text-transparent selection:bg-primary/20",
@@ -9,12 +9,12 @@ export function DiffPair({ added, deleted }: { added: number; deleted: number })
<DiffValue
sign="+"
value={added}
className="text-emerald-600/75 dark:text-emerald-300/75"
className="text-diff-added-foreground"
/>
<DiffValue
sign="-"
value={deleted}
className="text-rose-600/70 dark:text-rose-300/75"
className="text-diff-deleted-foreground"
/>
</span>
);
@@ -1,7 +1,6 @@
import { Suspense, lazy, type ReactNode } from "react";
import type { SyntaxHighlighterProps } from "react-syntax-highlighter";
import { useThemeValue } from "@/hooks/useTheme";
import type { RenderableFileDiffLine } from "@/lib/file-diff";
import { cn } from "@/lib/utils";
@@ -10,10 +9,6 @@ interface DiffSyntaxHighlightProps {
lines: RenderableFileDiffLine[];
}
interface LoadedDiffSyntaxHighlightProps extends DiffSyntaxHighlightProps {
isDark: boolean;
}
type RendererArgs = Parameters<NonNullable<SyntaxHighlighterProps["renderer"]>>[0];
type SyntaxNode = RendererArgs["rows"][number];
@@ -33,26 +28,21 @@ const LazyDiffSyntaxHighlight = lazy(async () => {
const [
{ default: SyntaxHighlighter },
{ default: createSyntaxElement },
{ default: oneDark },
{ default: oneLight },
] = await Promise.all([
import("react-syntax-highlighter/dist/esm/prism-async-light"),
import("react-syntax-highlighter/dist/esm/create-element"),
import("react-syntax-highlighter/dist/esm/styles/prism/one-dark"),
import("react-syntax-highlighter/dist/esm/styles/prism/one-light"),
]);
return {
default: function LoadedDiffSyntaxHighlight({
language,
lines,
isDark,
}: LoadedDiffSyntaxHighlightProps) {
const theme = isDark ? oneDark : oneLight;
}: DiffSyntaxHighlightProps) {
const code = lines.map((line) => line.content || " ").join("\n");
return (
<SyntaxHighlighter
language={language}
style={theme}
useInlineStyles={false}
style={{}}
PreTag="div"
CodeTag="div"
customStyle={{
@@ -71,6 +61,7 @@ const LazyDiffSyntaxHighlight = lazy(async () => {
},
}}
data-language={language}
className="code-content"
data-testid="syntax-highlighted-diff-hunk"
renderer={({ rows, stylesheet, useInlineStyles }) => (
<DiffLineTable
@@ -96,10 +87,9 @@ const LazyDiffSyntaxHighlight = lazy(async () => {
});
export function DiffSyntaxHighlight({ language, lines }: DiffSyntaxHighlightProps) {
const isDark = useThemeValue() === "dark";
return (
<Suspense fallback={<PlainDiffLines lines={lines} />}>
<LazyDiffSyntaxHighlight language={language} lines={lines} isDark={isDark} />
<LazyDiffSyntaxHighlight language={language} lines={lines} />
</Suspense>
);
}
@@ -148,22 +138,22 @@ function DiffLineRow({
<tr
className={cn(
"border-0",
kind === "add" && "bg-emerald-500/[0.09] dark:bg-emerald-300/[0.11]",
kind === "delete" && "bg-rose-500/[0.09] dark:bg-rose-300/[0.11]",
kind === "add" && "bg-diff-added",
kind === "delete" && "bg-diff-deleted",
)}
>
<td className="w-10 select-none border-r border-border/35 px-1.5 text-right text-muted-foreground/55">
<td className="w-10 select-none border-r border-border/35 px-1.5 text-right text-muted-foreground">
{line.old_lineno ?? ""}
</td>
<td className="w-10 select-none border-r border-border/35 px-1.5 text-right text-muted-foreground/55">
<td className="w-10 select-none border-r border-border/35 px-1.5 text-right text-muted-foreground">
{line.new_lineno ?? ""}
</td>
<td
className={cn(
"w-5 select-none px-1 text-center",
kind === "add" && "text-emerald-600/80 dark:text-emerald-300/85",
kind === "delete" && "text-rose-600/80 dark:text-rose-300/85",
kind === "context" && "text-muted-foreground/45",
kind === "add" && "text-diff-added-foreground",
kind === "delete" && "text-diff-deleted-foreground",
kind === "context" && "text-muted-foreground",
)}
>
{marker}
@@ -326,7 +326,7 @@ function FileUnifiedDiff({
aria-hidden
/>
<span className="min-w-0 flex-1">{viewDiffLabel}</span>
<span className="shrink-0 text-muted-foreground/65">{lineCountLabel}</span>
<span className="shrink-0 text-muted-foreground">{lineCountLabel}</span>
</button>
<DisclosureContent id={contentId} open={open} onExitComplete={releaseBody}>
{shouldRenderBody ? renderBody() : null}
@@ -35,13 +35,13 @@ export function ThinkingReasoningShell({
const headerClassName = "touch-target inline-flex h-7 min-w-0 items-center gap-1.5 rounded-md px-1.5";
const headerContent = (
<>
<Activity className={cn("h-3.5 w-3.5 shrink-0", active ? "activity-current" : "text-muted-foreground/65")} strokeWidth={1.5} aria-hidden>
<Activity className={cn("h-3.5 w-3.5 shrink-0", active ? "activity-current" : "text-muted-foreground")} strokeWidth={1.5} aria-hidden>
{active ? <path className="activity-current-trace" pathLength={100} d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" /> : null}
</Activity>
<span
data-sheen-text={active ? label : undefined}
className={cn(
"min-w-0 truncate text-[12px] font-normal leading-4 text-muted-foreground/65",
"min-w-0 truncate text-[12px] font-normal leading-4 text-muted-foreground",
active && "streaming-text-sheen",
)}
>