The best way to control Claude Code, Codex and more from any computer or phone
fix(web): chat text selection stays continuous while scrolling (#35074)
Julius Marminge committed
Nov 12, 2026 at 02:49 UTC
83ee96f48589298745dbee9d2a25d5575f315489
1 file changed
+51
-1
apps/web/src/components/chat/MessagesTimeline.tsx
+51
-1
@@ -854,7 +854,11 @@ const ConversationTimeline = memo(function ConversationTimeline({
854
const onAppFullscreenChange = (rowId: string, fullscreen: boolean) => {
855
setFullscreenAppRowId((current) => (fullscreen ? rowId : current === rowId ? null : current));
856
};
857
- const alwaysRenderIndices = restoringAlwaysRender?.indices ?? [];
857
+ const selectedRowIds = useSelectedTimelineRowIds(timelineViewportElement);
858
+ const alwaysRenderIndices = [
859
+ ...(restoringAlwaysRender?.indices ?? []),
860
+ ...timelineRowSpanIndices(rows, selectedRowIds),
861
+ ];
862
// Screen readers can only reach headings in the DOM. Keeping the first and
863
// last messages mounted lets heading navigation wrap to either end.
864
const firstMessageRow = rows.find(isMessageRow);
@@ -1522,6 +1526,52 @@ function isMessageRow(row: MessagesTimelineRow) {
1526
return row.kind === "message" && row.message.role !== "system";
1527
}
1528
1529
+// LegendList recycles a row's container once it leaves the draw buffer, which
1530
+// moves a native selection's ends onto other rows. Pin the selected rows.
1531
+function useSelectedTimelineRowIds(viewport: HTMLElement | null) {
1532
+ const [rowIds, setRowIds] = useState<ReadonlyArray<string>>([]);
1533
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes to document selectionchange to track which timeline rows a native selection covers
1534
+ useEffect(() => {
1535
+ if (!viewport) return;
1536
+ const update = () => {
1537
+ const selection = document.getSelection();
1538
+ const range =
1539
+ selection && !selection.isCollapsed && selection.rangeCount > 0
1540
+ ? selection.getRangeAt(0)
1541
+ : null;
1542
+ const next: string[] = [];
1543
+ if (range?.intersectsNode(viewport)) {
1544
+ for (const row of viewport.querySelectorAll<HTMLElement>("[data-timeline-row-id]")) {
1545
+ const rowId = row.dataset.timelineRowId;
1546
+ if (rowId && range.intersectsNode(row)) next.push(rowId);
1547
+ }
1548
+ }
1549
+ setRowIds((current) =>
1550
+ current.length === next.length && current.every((id, i) => id === next[i]) ? current : next,
1551
+ );
1552
+ };
1553
+ document.addEventListener("selectionchange", update);
1554
+ return () => {
1555
+ document.removeEventListener("selectionchange", update);
1556
+ setRowIds([]);
1557
+ };
1558
+ }, [viewport]);
1559
+ return rowIds;
1560
+}
1561
+
1562
+// Rows between the selected ones are covered too, even if not mounted right now.
1563
+function timelineRowSpanIndices(
1564
+ rows: ReadonlyArray<MessagesTimelineRow>,
1565
+ rowIds: ReadonlyArray<string>,
1566
+): number[] {
1567
+ if (rowIds.length === 0) return [];
1568
+ const selected = new Set(rowIds);
1569
+ const first = rows.findIndex((row) => selected.has(row.id));
1570
+ const last = rows.findLastIndex((row) => selected.has(row.id));
1571
+ if (first < 0) return [];
1572
+ return Array.from({ length: last - first + 1 }, (_, i) => first + i);
1573
+}
1574
+
1575
function keyExtractor(item: MessagesTimelineRow) {
1576
return item.id;
1577
}