The best way to control Claude Code, Codex and more from any computer or phone
fix(web): open citation comments with the caret at the end (#28667)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Kim Khoi Lam committed
Nov 9, 2026 at 21:28 UTC
2b1db482d0d4bac7b994ac2def1df7e220edbb11
2 files changed
+33
-3
apps/web/src/components/chat/AssistantCitationChip.browser.test.tsx
+26
-2
@@ -1,5 +1,6 @@
1
import {
2
ASSISTANT_CITATION_MAX_COMMENT_LENGTH,
3
+ type AssistantCitation,
4
EnvironmentId,
5
MessageId,
6
ThreadId,
@@ -50,12 +51,16 @@ function setup() {
51
return { sourceAnchor, [Symbol.dispose]: () => source.remove() };
52
}
53
53
-function mount(sourceAnchor: AssistantCitationSourceAnchor, onSave: () => boolean) {
54
+function mount(
55
+ sourceAnchor: AssistantCitationSourceAnchor | undefined,
56
+ onSave: () => boolean,
57
+ chipCitation: AssistantCitation = citation,
58
+) {
59
function Composer() {
60
const [open, setOpen] = useState(true);
61
return (
62
<AssistantCitationChip
58
- citation={citation}
63
+ citation={chipCitation}
64
composer
65
commentEditor={{ open, sourceAnchor, onOpenChange: setOpen, onSave }}
66
/>
@@ -128,6 +133,25 @@ describe("citation comment source disappearance", () => {
133
});
134
});
135
136
+describe("citation comment caret", () => {
137
+ it("opens a saved comment with the caret after its end, scrolled into view", async () => {
138
+ using _source = setup();
139
+ const comment = `${"line\n".repeat(40)}end`;
140
+ await using _screen = await mount(
141
+ undefined,
142
+ vi.fn(() => true),
143
+ { ...citation, comment },
144
+ );
145
+ await vi.waitFor(() => expect(document.activeElement).toBe(textarea()));
146
+ const input = textarea()!;
147
+
148
+ expect(input.scrollHeight).toBeGreaterThan(input.clientHeight);
149
+ expect(input.scrollTop).toBe(input.scrollHeight - input.clientHeight);
150
+ await userEvent.keyboard("!");
151
+ expect(input.value).toBe(`${comment}!`);
152
+ });
153
+});
154
+
155
describe("citation comment popup position", () => {
156
it("opens at its anchor instead of sliding in from the window corner", async () => {
157
using source = setup();
apps/web/src/components/chat/AssistantCitationChip.tsx
+7
-1
@@ -193,7 +193,13 @@ export function AssistantCitationChip({
193
align="end"
194
anchor={popupAnchor}
195
initialFocus={() => {
196
- commentInputRef.current?.focus({ preventScroll: true });
196
+ const input = commentInputRef.current;
197
+ if (input) {
198
+ input.focus({ preventScroll: true });
199
+ input.setSelectionRange(input.value.length, input.value.length);
200
+ // Moving the caret doesn't scroll a long comment to it.
201
+ input.scrollTop = input.scrollHeight;
202
+ }
203
return false;
204
}}
205
finalFocus={