The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
fix(web): scroll wide tables to the selected Find match (#39295)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 21:00 UTC
5bc2d512e470ed8f3ea6b5876118d9f3b39c4474
3 files changed
+164
-5
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+93
@@ -1841,6 +1841,99 @@ describe("MessagesTimeline thread find", () => {
1841
}
1842
const released = { source: "command", releasesFollow: true };
1843
1844
+ it("reveals the previous match in a table without scrolling a sibling table", async () => {
1845
+ setup();
1846
+ const columns = Array.from({ length: 12 }, (_, index) => `DiagnosticsColumn${index}`);
1847
+ const cells = ["needle", ...columns.slice(1, -1), "needle"];
1848
+ const table = [columns, columns.map(() => "---"), cells]
1849
+ .map((row) => `| ${row.join(" | ")} |`)
1850
+ .join("\n");
1851
+ const entry = message(`${table}\n\n${table}`);
1852
+ const props = {
1853
+ ...baseProps(),
1854
+ timelineEntries: [entry],
1855
+ liveFollowEnabled: false,
1856
+ findOpen: true,
1857
+ findExpanded: true,
1858
+ findQuery: "needle",
1859
+ };
1860
+ const element = (occurrence: number, navigationId: number) => (
1861
+ <MessagesTimeline
1862
+ {...props}
1863
+ activeFindMatch={{ entryId: entry.id, runId: null, occurrence }}
1864
+ findNavigationId={navigationId}
1865
+ />
1866
+ );
1867
+ await using screen = await renderElement(element(1, 1));
1868
+ const [viewport, sibling] = await vi.waitFor(() => {
1869
+ const tables = screen.container.querySelectorAll<HTMLElement>(
1870
+ '.chat-markdown-table-container [data-slot="scroll-area-viewport"]',
1871
+ );
1872
+ expect(tables).toHaveLength(2);
1873
+ return [tables[0]!, tables[1]!] as const;
1874
+ });
1875
+ viewport.scrollLeft = viewport.scrollWidth;
1876
+ sibling.scrollLeft = sibling.scrollWidth;
1877
+ const siblingOffset = sibling.scrollLeft;
1878
+ const clip = viewport.getBoundingClientRect();
1879
+ expect(viewport.querySelector("td")!.getBoundingClientRect().right).toBeLessThan(clip.left);
1880
+ expect(siblingOffset).toBeGreaterThan(0);
1881
+
1882
+ await screen.rerender(element(0, 2));
1883
+ await vi.waitFor(() => {
1884
+ const [match] = CSS.highlights.get("t3-thread-find-active") ?? [];
1885
+ if (!(match instanceof Range)) throw new Error("Missing active match range");
1886
+ expect(match.startContainer.parentElement?.closest("td")).toBe(viewport.querySelector("td"));
1887
+ expect(match.getBoundingClientRect().left).toBeGreaterThanOrEqual(clip.left - 1);
1888
+ });
1889
+ expect(sibling.scrollLeft).toBe(siblingOffset);
1890
+ });
1891
+
1892
+ it("reveals a match in a nested table clipped by the outer table", async () => {
1893
+ setup();
1894
+ const columns = Array.from({ length: 12 }, (_, index) => `<td>DiagnosticsColumn${index}</td>`);
1895
+ const entry = message(
1896
+ `<table><tbody><tr>${columns.join("")}<td><table><tbody><tr><td>needle</td></tr></tbody></table></td></tr></tbody></table>`,
1897
+ { role: "assistant" },
1898
+ );
1899
+ const props = {
1900
+ ...baseProps(),
1901
+ timelineEntries: [entry],
1902
+ liveFollowEnabled: false,
1903
+ findOpen: true,
1904
+ findExpanded: true,
1905
+ findQuery: "needle",
1906
+ };
1907
+ await using screen = await renderElement(<MessagesTimeline {...props} />);
1908
+ const outerViewport = await vi.waitFor(() => {
1909
+ const viewport = screen.container.querySelector(
1910
+ '.chat-markdown-table-container [data-slot="scroll-area-viewport"]',
1911
+ );
1912
+ const nestedCell = viewport?.querySelector("table table td");
1913
+ expect(nestedCell?.textContent).toBe("needle");
1914
+ expect(nestedCell!.getBoundingClientRect().left).toBeGreaterThan(
1915
+ viewport!.getBoundingClientRect().right,
1916
+ );
1917
+ return viewport!;
1918
+ });
1919
+
1920
+ await screen.rerender(
1921
+ <MessagesTimeline
1922
+ {...props}
1923
+ activeFindMatch={{ entryId: entry.id, runId: null, occurrence: 0 }}
1924
+ findNavigationId={1}
1925
+ />,
1926
+ );
1927
+ await vi.waitFor(() => {
1928
+ const [match] = CSS.highlights.get("t3-thread-find-active") ?? [];
1929
+ if (!(match instanceof Range)) throw new Error("Missing active match range");
1930
+ const bounds = match.getBoundingClientRect();
1931
+ const clip = outerViewport.getBoundingClientRect();
1932
+ expect(bounds.left).toBeGreaterThanOrEqual(clip.left - 1);
1933
+ expect(bounds.right).toBeLessThanOrEqual(clip.right + 1);
1934
+ });
1935
+ });
1936
+
1937
it("releases follow once when it starts showing a thread whose find is open", async () => {
1938
setup();
1939
const { navigations, element } = renderObserved();
apps/web/src/components/chat/useThreadFindNavigation.ts
+14
-5
@@ -4,6 +4,8 @@ import type { ThreadFindMatch } from "./threadFind";
4
import { useThreadFindHighlights } from "./threadFindHighlights";
5
6
const FIND_MATCH_VIEW_MARGIN = 96;
7
+const FIND_SCROLL_VIEWPORT_SELECTOR =
8
+ 'pre, .chat-markdown-table-container [data-slot="scroll-area-viewport"]';
9
10
type FindEntries = readonly { readonly id: string }[];
11
@@ -124,13 +126,20 @@ function revealThreadFindMatch(
126
return;
127
}
128
127
- const codeScroller = range.startContainer.parentElement?.closest("pre");
128
- if (codeScroller) {
129
+ for (
130
+ let horizontalViewport = range.startContainer.parentElement?.closest<HTMLElement>(
131
+ FIND_SCROLL_VIEWPORT_SELECTOR,
132
+ );
133
+ horizontalViewport;
134
+ horizontalViewport = horizontalViewport.parentElement?.closest<HTMLElement>(
135
+ FIND_SCROLL_VIEWPORT_SELECTOR,
136
+ )
137
+ ) {
138
const rect = range.getBoundingClientRect();
130
- const viewport = codeScroller.getBoundingClientRect();
131
- if (rect.left < viewport.left) codeScroller.scrollLeft += rect.left - viewport.left - 16;
139
+ const viewport = horizontalViewport.getBoundingClientRect();
140
+ if (rect.left < viewport.left) horizontalViewport.scrollLeft += rect.left - viewport.left - 16;
141
else if (rect.right > viewport.right)
133
- codeScroller.scrollLeft += rect.right - viewport.right + 16;
142
+ horizontalViewport.scrollLeft += rect.right - viewport.right + 16;
143
}
144
const rect = range.getBoundingClientRect();
145
const viewport = container?.getBoundingClientRect();
scripts/scenarios/find-reveals-clipped-table-cell.e2e.ts
new
+57
@@ -0,0 +1,57 @@
1
+/// <reference lib="dom" />
2
+import { expect } from "e2e";
3
+
4
+import { test, WEB } from "./t3.ts";
5
+
6
+const MATCH = "quartzneedle";
7
+const columns = Array.from({ length: 16 }, (_, index) => `DiagnosticsColumn${index + 1}`);
8
+const row = (cells: string[]) => `| ${cells.join(" | ")} |`;
9
+const TABLE = [
10
+ row(columns),
11
+ row(columns.map(() => "---")),
12
+ row([...columns.slice(0, -1).map(() => "pending"), MATCH]),
13
+].join("\n");
14
+
15
+test(
16
+ "Find reveals a match in the last column of a wide table",
17
+ WEB,
18
+ async ({ t3, app, screen, browser }) => {
19
+ const project = await t3.project("wide-table");
20
+ const thread = await t3.thread({ project, title: "Diagnostics table", messages: [TABLE] });
21
+ await t3.open(thread);
22
+ await screen.getByText("first fixture turn complete", { exact: false }).waitFor({
23
+ timeout: 120_000,
24
+ });
25
+
26
+ await browser.keyboard.press("Control+f");
27
+ const find = screen.getByRole("searchbox", "Find in thread");
28
+ await find.fill(MATCH);
29
+
30
+ try {
31
+ await expect
32
+ .poll(
33
+ () =>
34
+ browser.evaluate((query) => {
35
+ const active = CSS.highlights.get("t3-thread-find-active");
36
+ const match =
37
+ active &&
38
+ [...active].find((range) => range instanceof Range && range.toString() === query);
39
+ const viewport = match?.startContainer.parentElement?.closest(
40
+ '.chat-markdown-table-container [data-slot="scroll-area-viewport"]',
41
+ );
42
+ if (!(match instanceof Range) || !viewport)
43
+ return "Table match has no active highlight";
44
+ const rect = match.getBoundingClientRect();
45
+ const clip = viewport.getBoundingClientRect();
46
+ return rect.height > 0 && rect.left >= clip.left - 1 && rect.right <= clip.right + 1
47
+ ? "Selected table match is inside the horizontal viewport"
48
+ : "Selected table match is clipped horizontally";
49
+ }, MATCH),
50
+ { timeout: 20_000 },
51
+ )
52
+ .toBe("Selected table match is inside the horizontal viewport");
53
+ } finally {
54
+ await app.screenshot("selected-table-match");
55
+ }
56
+ },
57
+);