-
-
-
+
{/* Stays within the row's px-1: the chat lane clips sideways overflow. */}
-
-
);
}
diff --git a/apps/web/src/components/chat/TimelineAssistantRows.tsx b/apps/web/src/components/chat/TimelineAssistantRows.tsx
index b62f6f8e4b10f..7a29cc7f4c924 100644
--- a/apps/web/src/components/chat/TimelineAssistantRows.tsx
+++ b/apps/web/src/components/chat/TimelineAssistantRows.tsx
@@ -53,7 +53,7 @@ export function AssistantTimelineRow({ row }: { row: Extract
T3 Code
-
+
node.type === "element" && node.tagName === "table",
+ );
+ if (!table) throw new Error("no table");
+ return table;
+}
+
+describe("markdownTableMinWidth", () => {
+ it("keeps short columns at their longest cell and caps long ones at the floor", () => {
+ const table = tableFrom(
+ [
+ "| # | Approach | Notes |",
+ "| - | --- | --- |",
+ "| 1 | Breakout | Grows past the reading column into the free pane width |",
+ "| 12 | Scroll | **Keeps** the column |",
+ ].join("\n"),
+ );
+ expect(markdownTableMinWidth(table)).toEqual({
+ ch: 2 + "Breakout".length + MARKDOWN_TABLE_COLUMN_FLOOR_CH,
+ columns: 3,
+ });
+ const spaced = tableFrom(["| A |", "| - |", "| **a** **b** **c** **d** |"].join("\n"));
+ expect(markdownTableMinWidth(spaced)).toEqual({ ch: "a b c d".length, columns: 1 });
+ });
+
+ it("sums a floor per column, so many long columns outgrow a narrow lane", () => {
+ const cell = "a long explanation that would otherwise wrap into a tall block";
+ const row = `| ${Array.from({ length: 7 }, () => cell).join(" | ")} |`;
+ const table = tableFrom(
+ [
+ `| ${Array.from({ length: 7 }, (_, index) => `Column ${index}`).join(" | ")} |`,
+ `| ${Array.from({ length: 7 }, () => "---").join(" | ")} |`,
+ row,
+ ].join("\n"),
+ );
+ expect(markdownTableMinWidth(table)).toEqual({
+ ch: 7 * MARKDOWN_TABLE_COLUMN_FLOOR_CH,
+ columns: 7,
+ });
+ });
+
+ it("returns null without a table", () => {
+ expect(markdownTableMinWidth(undefined)).toBeNull();
+ });
+});
diff --git a/apps/web/src/components/chat/markdownTableLayout.ts b/apps/web/src/components/chat/markdownTableLayout.ts
new file mode 100644
index 0000000000000..8a5e9776141c3
--- /dev/null
+++ b/apps/web/src/components/chat/markdownTableLayout.ts
@@ -0,0 +1,47 @@
+import type { Element, ElementContent } from "hast";
+
+/** Widest a column's floor gets, in characters; longer cells wrap above it. */
+export const MARKDOWN_TABLE_COLUMN_FLOOR_CH = 16;
+
+function textContent(node: ElementContent): string {
+ if (node.type === "text") return node.value;
+ if (node.type !== "element") return "";
+ let text = "";
+ for (const child of node.children) text += textContent(child);
+ return text;
+}
+
+function* tableRows(node: Element): Generator {
+ for (const child of node.children) {
+ if (child.type !== "element") continue;
+ if (child.tagName === "tr") yield child;
+ else if (child.tagName === "thead" || child.tagName === "tbody" || child.tagName === "tfoot") {
+ yield* tableRows(child);
+ }
+ }
+}
+
+/**
+ * The narrowest a table can get before its cells turn into tall, hard-to-scan
+ * blocks: each column keeps room for its longest cell, up to the floor. Narrow
+ * columns such as numbers keep their natural width. Returns the summed floor in
+ * `ch` and the column count, or null when the table has no cells.
+ */
+export function markdownTableMinWidth(
+ table: Element | undefined,
+): { readonly ch: number; readonly columns: number } | null {
+ if (!table) return null;
+ const longest: number[] = [];
+ for (const row of tableRows(table)) {
+ let column = 0;
+ for (const cell of row.children) {
+ if (cell.type !== "element" || (cell.tagName !== "th" && cell.tagName !== "td")) continue;
+ longest[column] = Math.max(longest[column] ?? 0, textContent(cell).trim().length);
+ column += 1;
+ }
+ }
+ if (longest.length === 0) return null;
+ let ch = 0;
+ for (const length of longest) ch += Math.min(length, MARKDOWN_TABLE_COLUMN_FLOOR_CH);
+ return { ch, columns: longest.length };
+}
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index 771c714b1ff8a..5b4655877e57d 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -2258,10 +2258,12 @@ code {
/* Diagnostics-style tables: row separators only, and a scroll-fade container
for horizontal overflow. Cells wrap and the table fits its lane. The root
chat-markdown wrapping rules (overflow-wrap: anywhere) would let columns
- shrink to single characters, so restore word-boundary wrapping: the min
- column width is the longest word, and only wider content scrolls. */
+ shrink to single characters, so restore word-boundary wrapping. Each column
+ also keeps a floor (MarkdownTable's --markdown-table-floor) so many long
+ columns scroll instead of collapsing into tall, narrow blocks. */
.chat-markdown table {
width: 100%;
+ min-width: var(--markdown-table-floor, 0);
border-collapse: collapse;
overflow-wrap: normal;
word-break: normal;
@@ -2308,6 +2310,82 @@ code {
max-width: none;
}
+/* Expand only helps a table that does not fit. */
+.chat-markdown-table-container:not(:has([data-has-overflow-x])) .chat-markdown-table-expand {
+ display: none;
+}
+
+/* A scrolled table keeps its first column in view. The left edge fade would
+ dim that column, so only the right edge fades. */
+.chat-markdown-table-container [data-has-overflow-x] {
+ --tw-mask-left: linear-gradient(#000, #000);
+}
+
+.chat-markdown-table-container [data-has-overflow-x] :is(th, td):first-child,
+.chat-markdown-table-expanded :is(th, td):first-child {
+ position: sticky;
+ inset-inline-start: 0;
+ z-index: 1;
+ background: var(--background);
+ box-shadow: inset -1px 0 0 color-mix(in srgb, var(--contrast-border) 60%, transparent);
+}
+
+.chat-markdown-table-expanded thead th {
+ position: sticky;
+ top: 0;
+ z-index: 2;
+ background: var(--background);
+ box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--contrast-border) 60%, transparent);
+}
+
+.chat-markdown-table-expanded thead th:first-child {
+ z-index: 3;
+ box-shadow:
+ inset -1px 0 0 color-mix(in srgb, var(--contrast-border) 60%, transparent),
+ inset 0 -1px 0 color-mix(in srgb, var(--contrast-border) 60%, transparent);
+}
+
+/* Edge padding lives on the cells: sticky cells pin to the scroller's padding
+ edge, so scroller padding would let scrolled columns show beside them. */
+.chat-markdown-table-expanded :is(th, td) {
+ max-width: 32rem;
+}
+
+.chat-markdown-table-expanded :is(th, td):first-child {
+ padding-inline-start: 1rem;
+}
+
+.chat-markdown-table-expanded :is(th, td):last-child {
+ padding-inline-end: 1rem;
+}
+
+/* Assistant replies let a wide table grow past the reading column, centred on
+ it, up to the timeline row (the pane minus its gutters). Prose stays at the
+ chat width. Past the row width the table wraps and then scrolls as before. */
+.messages-timeline-row-frame {
+ container: chat-row / inline-size;
+}
+
+@container chat-row (width > 0) {
+ .chat-content-lane:has([data-chat-wide-content] .chat-markdown-table-breakout) {
+ overflow-x: visible;
+ }
+
+ [data-chat-wide-content] .chat-markdown > .chat-markdown-table-container {
+ .chat-markdown-table-breakout {
+ display: flex;
+ justify-content: center;
+ }
+
+ .chat-markdown-table-breakout > :first-child {
+ flex: none;
+ width: max-content;
+ min-width: 100%;
+ max-width: 100cqw;
+ }
+ }
+}
+
/* Keep overflow discoverable when the edge fade falls between columns. */
.chat-markdown
.chat-markdown-table-container