@devries-cameron20 / t3code Mirror · read-only / commits / 159f2b8cc3
Fork 0

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 22, 19:30 UTC

fix(web): quote comment box stays on screen for long code lines (#22149)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Etan Heyman committed Oct 22, 2026 at 01:11 UTC 159f2b8cc33a46c2dfed7d394ec8eb54bad03c03
2 files changed +59 -1
apps/web/src/components/chat/AssistantCitationChip.browser.test.tsx
+50
@@ -6,8 +6,10 @@ import {
6 } from "@t3tools/contracts";
7 import { useState, type ReactNode } from "react";
8 import { describe, expect, it, vi } from "vite-plus/test";
9 +import { userEvent } from "vite-plus/test/browser";
10
11 import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
12 +import "~/index.css";
13 import { act, render } from "../../../test/render";
14
15 const mocks = vi.hoisted(() => ({ observeSource: vi.fn(), dispose: vi.fn() }));
@@ -125,3 +127,51 @@ describe("citation comment source disappearance", () => {
127 expect(textarea()).toBeNull();
128 });
129 });
130 +
131 +describe("citation comment popup position", () => {
132 + it("stays on screen when the cited text ends in a code block's hidden overflow", async () => {
133 + using _source = setup();
134 + const message = document.createElement("div");
135 + message.className = "chat-markdown";
136 + message.style.width = "240px";
137 + const pre = document.createElement("pre");
138 + const code = document.createElement("code");
139 + // Highlighted code is split into token spans, so the range's last client rect
140 + // covers only the final token, wholly inside the hidden overflow.
141 + for (let index = 0; index < 40; index += 1) {
142 + const token = document.createElement("span");
143 + token.textContent = `token${index} `;
144 + code.append(token);
145 + }
146 + pre.append(code);
147 + message.append(pre);
148 + document.body.prepend(message);
149 + using _message = { [Symbol.dispose]: () => message.remove() };
150 + const range = document.createRange();
151 + range.selectNodeContents(code);
152 + const rects = range.getClientRects();
153 + expect(rects.item(rects.length - 1)!.left).toBeGreaterThan(window.innerWidth);
154 + const sourceAnchor = {
155 + source: message,
156 + range,
157 + viewport: document.body,
158 + } as AssistantCitationSourceAnchor;
159 +
160 + await using _screen = await mount(
161 + sourceAnchor,
162 + vi.fn(() => true),
163 + );
164 + const popup = () => document.querySelector<HTMLElement>('[data-slot="popover-popup"]');
165 + await vi.waitFor(() => expect(popup()?.getBoundingClientRect().width).toBeGreaterThan(0));
166 + // Typing scrolls ancestors to reveal the caret, which shifts the whole app
167 + // sideways when the box is off screen.
168 + await userEvent.keyboard("note");
169 +
170 + expect(textarea()?.value).toBe("note");
171 + expect(document.scrollingElement?.scrollLeft).toBe(0);
172 + expect(document.body.scrollLeft).toBe(0);
173 + const rect = popup()!.getBoundingClientRect();
174 + expect(rect.left).toBeGreaterThanOrEqual(0);
175 + expect(rect.right).toBeLessThanOrEqual(window.innerWidth);
176 + });
177 +});
apps/web/src/components/chat/AssistantCitationChip.tsx
+9 -1
@@ -94,7 +94,15 @@ export function AssistantCitationChip({
94 contextElement: activeSourceAnchor.source,
95 getBoundingClientRect: () => {
96 const rects = activeSourceAnchor.range.getClientRects();
97 - return rects.item(rects.length - 1) ?? activeSourceAnchor.range.getBoundingClientRect();
97 + const rect =
98 + rects.item(rects.length - 1) ?? activeSourceAnchor.range.getBoundingClientRect();
99 + // Code blocks and tables scroll sideways inside the message, so the cited
100 + // text can end in their hidden overflow. Base UI only shifts the popup while
101 + // it still touches the anchor, so clamp the anchor to the message's width.
102 + const bounds = activeSourceAnchor.source.getBoundingClientRect();
103 + const left = Math.min(Math.max(rect.left, bounds.left), bounds.right);
104 + const right = Math.max(Math.min(rect.right, bounds.right), left);
105 + return new DOMRect(left, rect.top, right - left, rect.height);
106 },
107 }
108 : undefined;