style(webui): refine Markdown reading typography (#6568)

* style(webui): refine Markdown reading typography

* fix(webui): stabilize composer and typography checks
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-05 15:54:17 +08:00
1 parent 0c92d5bb03
commit e6127aa324
17 files changed
+307 -100

No files matched your search

-4
View File
@@ -29,10 +29,6 @@
padding-inline: calc(var(--math-tag-width) + 1em);
}
.markdown-content:has(.math-fit) {
--cjk-line-height: 1.65;
}
.markdown-content li .math-fit {
margin-block: 0.3em 0.35em;
}
@@ -831,9 +831,6 @@ export default function MarkdownTextRenderer({
components={components}
className={cn(
"markdown-content prose max-w-none dark:prose-invert",
"prose-headings:mt-4 prose-headings:mb-2 prose-headings:tracking-tight",
"prose-p:my-2",
"prose-ul:my-2 prose-ol:my-2 prose-li:my-0.5",
"prose-blockquote:my-3 prose-blockquote:border-l-2 prose-blockquote:font-normal",
"prose-blockquote:not-italic prose-blockquote:text-foreground/80",
"prose-a:text-content-link prose-a:underline-offset-2 hover:prose-a:text-content-link-hover",
+95 -32
View File
@@ -1119,6 +1119,9 @@ export function ThreadComposer({
const [initialDraft] = useState(() => draftKey ? draftStore?.get(draftKey, persistDraft) : undefined);
const [value, setValue] = useState(initialDraft?.text ?? "");
const [composerFocused, setComposerFocused] = useState(false);
const [placeholderHintRequested, setPlaceholderHintRequested] = useState(false);
const [placeholderHintOpen, setPlaceholderHintOpen] = useState(false);
const [placeholderHintBottomGap, setPlaceholderHintBottomGap] = useState(0);
const blurFrame = useRef<number | null>(null);
const [boundSessionMentions, setBoundSessionMentions] = useState<SessionMention[]>(
initialDraft?.sessionMentions ?? [],
@@ -1164,8 +1167,21 @@ export function ThreadComposer({
const textareaRef = useRef<HTMLTextAreaElement>(null);
const mentionOverlayRef = useRef<HTMLDivElement>(null);
const formRef = useRef<HTMLFormElement>(null);
const tabFocusRequested = useRef(false);
const [compactControls, setCompactControls] = useState(false);
useEffect(() => {
// Automatic session focus should not open the hint; keyboard navigation should.
const onKeyDown = (event: KeyboardEvent) => { tabFocusRequested.current = event.key === "Tab"; };
const onPointerDown = () => { tabFocusRequested.current = false; };
document.addEventListener("keydown", onKeyDown, true);
document.addEventListener("pointerdown", onPointerDown, true);
return () => {
document.removeEventListener("keydown", onKeyDown, true);
document.removeEventListener("pointerdown", onPointerDown, true);
};
}, []);
useLayoutEffect(() => {
const form = formRef.current;
if (!form) return;
@@ -1853,6 +1869,26 @@ export function ThreadComposer({
if (input) autosizeTextarea(input);
}, [readingTextSize, customReadingTextSize]);
useLayoutEffect(() => {
const input = textareaRef.current;
if (!input || document.activeElement !== input || !placeholderHintRequested || input.value || !input.placeholder) {
setPlaceholderHintOpen(false);
return;
}
const form = formRef.current!;
const measure = () => {
setPlaceholderHintOpen(input.scrollWidth > input.clientWidth);
setPlaceholderHintBottomGap(form.getBoundingClientRect().bottom - input.getBoundingClientRect().bottom);
};
measure();
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(measure);
observer?.observe(input);
observer?.observe(form);
let active = true;
void document.fonts?.ready.then(() => { if (active) measure(); });
return () => { active = false; observer?.disconnect(); };
}, [placeholderHintRequested, mentionInput.value, resolvedPlaceholder, sessionDragPreview, readingTextSize, customReadingTextSize]);
// Runs before paint so switching sessions never flashes stale draft text.
useLayoutEffect(() => {
if (previousPendingQueueKeyRef.current === pendingQueueKey) return;
@@ -2739,38 +2775,65 @@ export function ThreadComposer({
: null}
/>
) : null}
<textarea
ref={textareaRef}
value={mentionInput.value}
onFocus={() => {
if (compactWhenIdle) setComposerFocused(true);
}}
onChange={mentionInput.onChange}
onCompositionStart={mentionInput.onCompositionStart}
onCompositionEnd={mentionInput.onCompositionEnd}
onKeyDown={onKeyDown}
onKeyUp={() => setCursorPosition(rawSelection().start)}
onSelect={() => setCursorPosition(rawSelection().start)}
onClick={() => setCursorPosition(rawSelection().start)}
onCopy={mentionInput.onCopy}
onCut={mentionInput.onCut}
onScroll={(e) => {
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
}}
onPaste={onPaste}
rows={1}
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
placeholder={sessionDragPreview ? "" : resolvedPlaceholder}
disabled={interactionDisabled}
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
className={cn(
inputTextClasses,
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
"focus:outline-none focus-visible:outline-none",
"disabled:cursor-not-allowed",
hasInlineDecorations && "text-transparent selection:bg-primary/20",
)}
/>
<TooltipProvider>
<Tooltip open={placeholderHintOpen}>
<TooltipTrigger asChild>
<textarea
ref={textareaRef}
value={mentionInput.value}
onFocus={(event) => {
if (tabFocusRequested.current && !event.currentTarget.value) setPlaceholderHintRequested(true);
tabFocusRequested.current = false;
if (compactWhenIdle) setComposerFocused(true);
}}
onBlur={() => {
if (placeholderHintRequested) setPlaceholderHintRequested(false);
}}
onPointerLeave={(event) => {
if (event.pointerType === "mouse" && placeholderHintRequested) setPlaceholderHintRequested(false);
}}
onChange={mentionInput.onChange}
onCompositionStart={mentionInput.onCompositionStart}
onCompositionEnd={mentionInput.onCompositionEnd}
onKeyDown={onKeyDown}
onKeyUp={() => setCursorPosition(rawSelection().start)}
onSelect={() => setCursorPosition(rawSelection().start)}
onClick={(event) => {
setCursorPosition(rawSelection().start);
if (!event.currentTarget.value) setPlaceholderHintRequested(true);
}}
onCopy={mentionInput.onCopy}
onCut={mentionInput.onCut}
onScroll={(e) => {
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = e.currentTarget.scrollTop;
}}
onPaste={onPaste}
rows={1}
enterKeyHint={hasCoarsePointer ? "enter" : undefined}
placeholder={sessionDragPreview ? "" : resolvedPlaceholder}
disabled={interactionDisabled}
aria-label={inputAriaLabel ?? t("thread.composer.inputAria")}
aria-description={sessionDragPreview ? undefined : resolvedPlaceholder}
className={cn(
inputTextClasses,
"relative z-10 block caret-foreground placeholder:text-muted-foreground",
"focus:outline-none focus-visible:outline-none",
"disabled:cursor-not-allowed",
hasInlineDecorations && "text-transparent selection:bg-primary/20",
)}
/>
</TooltipTrigger>
{placeholderHintOpen ? (
<TooltipContent side="top" align="start" onEscapeKeyDown={() => {
setPlaceholderHintOpen(false);
setPlaceholderHintRequested(false);
}} style={{ "--placeholder-hint-bottom-gap": `${placeholderHintBottomGap}px` } as CSSProperties}
className="pointer-events-none max-w-[min(24rem,calc(100vw-2rem))] whitespace-normal break-words text-sm data-[side=bottom]:mt-[var(--placeholder-hint-bottom-gap)]">
{resolvedPlaceholder}
</TooltipContent>
) : null}
</Tooltip>
</TooltipProvider>
</div>
{inlineError ? (
<div