Skip to content

Commit eb751fa

Browse files
t3dotggclaude
andauthored
fix(web): chat tables open at the right size instead of collapsed and cut off (pingdotgg#26449)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c280e64 commit eb751fa

6 files changed

Lines changed: 30 additions & 79 deletions

File tree

‎apps/web/src/components/chat/MarkdownExternalLink.tsx‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ function leadingExternalLinkTextLength(text: string): number {
5454
return Math.min(text.length, 1);
5555
}
5656

57+
// Long words such as URLs can break after any character so they fit narrow
58+
// table columns. Short ones, like a PR number, stay whole.
5759
function breakableExternalLinkText(text: string): ReactNode[] {
58-
return Array.from(text, (character, index) => (
59-
<Fragment key={`${index}:${character}`}>
60-
{character}
61-
<wbr />
62-
</Fragment>
63-
));
60+
return Array.from(text.matchAll(/\s+|\S+/g), ({ 0: word, index: start }) =>
61+
word.length <= 16
62+
? word
63+
: Array.from(word, (character, offset) => (
64+
<Fragment key={`${start + offset}:${character}`}>
65+
{character}
66+
<wbr />
67+
</Fragment>
68+
)),
69+
);
6470
}
6571

6672
export function MarkdownExternalLinkContent({

‎apps/web/src/components/chat/MarkdownTable.tsx‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Check, Copy, Maximize2, Minimize2 } from "lucide";
2-
import { useRef, useState, type ComponentProps } from "react";
1+
import { Check, Copy } from "lucide";
2+
import { useRef, type ComponentProps } from "react";
33

44
import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
5-
import { getClientSettings } from "../../hooks/useSettings";
65
import {
76
serializeTableElementToCsv,
87
serializeTableElementToMarkdown,
@@ -16,13 +15,11 @@ import { reportMarkdownActionFailure } from "./markdownActionFailure";
1615

1716
export function MarkdownTable({ children, ...props }: ComponentProps<"table">) {
1817
const containerRef = useRef<HTMLDivElement | null>(null);
19-
const [expanded, setExpanded] = useState(() => getClientSettings().wordWrap);
2018
const { copyToClipboard, isCopied: copied } = useCopyToClipboard<"markdown" | "csv">({
2119
timeout: 1200,
2220
onError: (cause, format) =>
2321
reportMarkdownActionFailure({ operation: "copy-table", format }, cause),
2422
});
25-
const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
2623
const copyLabel = copied ? "Copied" : "Copy table";
2724

2825
const handleCopy = (format: "markdown" | "csv") => {
@@ -37,33 +34,12 @@ export function MarkdownTable({ children, ...props }: ComponentProps<"table">) {
3734
};
3835

3936
return (
40-
<div
41-
ref={containerRef}
42-
className="chat-markdown-table-container"
43-
data-expanded={expanded ? "true" : "false"}
44-
>
37+
<div ref={containerRef} className="chat-markdown-table-container">
4538
<ScrollArea radius="none" chainVerticalScroll scrollFade className="w-full max-w-full">
4639
<table {...props}>{children}</table>
4740
</ScrollArea>
4841
{/* Stays within the row's px-1: the chat lane clips sideways overflow. */}
49-
<div className="mt-0.5 -mx-1 flex items-center justify-between select-none">
50-
<Tooltip>
51-
<TooltipTrigger
52-
render={
53-
<Button
54-
type="button"
55-
variant={expanded ? "secondary" : "ghost-muted"}
56-
size="icon-xs"
57-
aria-pressed={expanded}
58-
onClick={() => setExpanded((value) => !value)}
59-
aria-label={expandLabel}
60-
/>
61-
}
62-
>
63-
<MorphIcon className="size-3" icon={expanded ? Minimize2 : Maximize2} />
64-
</TooltipTrigger>
65-
<TooltipPopup side="top">{expandLabel}</TooltipPopup>
66-
</Tooltip>
42+
<div className="mt-0.5 -mx-1 flex items-center justify-end select-none">
6743
<Menu>
6844
<Tooltip>
6945
<TooltipTrigger

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
12211221
>
12221222
<div
12231223
ref={observeLaneWidth}
1224-
className="@container/chat-lane chat-content-lane overflow-x-clip"
1224+
className="chat-content-lane overflow-x-clip"
12251225
data-timeline-root="true"
12261226
>
12271227
<AudioPreviewUnmountContext value={onAudioUnmount}>
@@ -1241,10 +1241,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
12411241
{unmatchedPendingApprovals.size > 0 ? (
12421242
<TimelineRowCtx value={sharedState}>
12431243
<div className="messages-timeline-row-frame">
1244-
<div
1245-
className="@container/chat-lane chat-content-lane overflow-x-clip"
1246-
data-timeline-root="true"
1247-
>
1244+
<div className="chat-content-lane overflow-x-clip" data-timeline-root="true">
12481245
<WorkLogBlock>
12491246
{[...unmatchedPendingApprovals.values()].map((approval) => (
12501247
<TimelinePendingApprovalRow key={approval.requestId} approval={approval} />

‎apps/web/src/components/settings/TypographySettings.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function WordWrapRow() {
235235
return (
236236
<SettingsRow
237237
{...searchableSetting("word-wrap")}
238-
description="Wrap long lines in code blocks, tables, diffs, and file previews by default."
238+
description="Wrap long lines in code blocks, diffs, and file previews by default."
239239
resetAction={
240240
settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? (
241241
<SettingResetButton
@@ -248,7 +248,7 @@ function WordWrapRow() {
248248
<Switch
249249
checked={settings.wordWrap}
250250
onCheckedChange={(checked) => updateSettings({ wordWrap: Boolean(checked) })}
251-
aria-label="Wrap code, tables, diffs, and file previews by default"
251+
aria-label="Wrap code, diffs, and file previews by default"
252252
/>
253253
}
254254
/>

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ export const SETTINGS_SEARCH_ITEMS = [
380380
id: "word-wrap",
381381
title: "Word wrap",
382382
to: "/settings/appearance",
383-
searchTerms: ["long lines code blocks tables diffs file previews"],
383+
searchTerms: ["long lines code blocks diffs file previews"],
384384
},
385385
{
386386
id: "composer-context",

‎apps/web/src/index.css‎

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,14 +2193,13 @@ code {
21932193
}
21942194
}
21952195

2196-
/* Diagnostics-style tables: row separators only, uppercase headers, and a
2197-
scroll-fade container for horizontal overflow. The root chat-markdown
2198-
wrapping rules (overflow-wrap: anywhere) would let columns shrink to single
2199-
characters and defeat the overflow — restore word-boundary wrapping so the
2200-
min column width is the longest word. */
2196+
/* Diagnostics-style tables: row separators only, and a scroll-fade container
2197+
for horizontal overflow. Cells wrap and the table fits its lane. The root
2198+
chat-markdown wrapping rules (overflow-wrap: anywhere) would let columns
2199+
shrink to single characters, so restore word-boundary wrapping: the min
2200+
column width is the longest word, and only wider content scrolls. */
22012201
.chat-markdown table {
22022202
width: 100%;
2203-
min-width: max-content;
22042203
border-collapse: collapse;
22052204
overflow-wrap: normal;
22062205
word-break: normal;
@@ -2230,48 +2229,21 @@ code {
22302229
border-bottom: 1px solid color-mix(in srgb, var(--contrast-border) 60%, transparent);
22312230
padding-block: 0.55rem;
22322231
font-weight: 600;
2233-
white-space: nowrap;
22342232
}
22352233

22362234
.chat-markdown tbody td {
22372235
border-bottom: 1px solid color-mix(in srgb, var(--contrast-border) 60%, transparent);
22382236
}
22392237

2240-
/* Collapsed (default): single-line cells truncate so arbitrary chat content
2241-
cannot blow the column out; the footer toggle expands cells to wrap. */
2242-
.chat-markdown .chat-markdown-table-container[data-expanded="false"] th,
2243-
.chat-markdown .chat-markdown-table-container[data-expanded="false"] td {
2244-
overflow: hidden;
2238+
/* Caps a long path, URL, or chip at 24rem; text past the cap wraps. */
2239+
.chat-markdown :is(th, td) {
22452240
max-width: 24rem;
2246-
text-overflow: ellipsis;
2247-
white-space: nowrap;
2248-
}
2249-
2250-
.chat-markdown .chat-markdown-table-container[data-expanded="true"] td {
2251-
max-width: 24rem;
2252-
overflow-wrap: anywhere;
2253-
}
2254-
2255-
/* Fit expanded tables to wide timeline lanes; narrow lanes keep horizontal
2256-
scrolling so prose columns remain readable. */
2257-
@container chat-lane (min-width: 36rem) {
2258-
.chat-markdown .chat-markdown-table-container[data-expanded="true"] table {
2259-
min-width: 0;
2260-
}
2261-
2262-
.chat-markdown .chat-markdown-table-container[data-expanded="true"] th {
2263-
white-space: normal;
2264-
}
2265-
2266-
.chat-markdown .chat-markdown-table-container[data-expanded="true"] td {
2267-
overflow-wrap: break-word;
2268-
}
2241+
overflow-wrap: break-word;
22692242
}
22702243

22712244
/* Formula cells keep their natural width and scroll with the table. */
2272-
.chat-markdown .chat-markdown-table-container td:has([data-markdown-math]) {
2245+
.chat-markdown :is(th, td):has([data-markdown-math]) {
22732246
max-width: none;
2274-
overflow: visible;
22752247
}
22762248

22772249
:root {

0 commit comments

Comments
 (0)