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 23, 21:45 UTC
fix(web): return focus to the composer after saving a citation note (#13450)
MacKinley Smith committed
Sep 25, 2026 at 13:43 UTC
a4f6078bebcb3283e53e1cea247257136ce82cc8
2 files changed
+75
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+55
@@ -29,6 +29,7 @@ import {
29
useMemo,
30
useRef,
31
useState,
32
+ type KeyboardEvent as ReactKeyboardEvent,
33
} from "react";
34
import { EditorContent, useEditor } from "@tiptap/react";
35
@@ -371,6 +372,16 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
372
.run();
373
}, [editor, nodePos]);
374
375
+ // Put the caret right after the chip so Enter sends and typing continues the prompt.
376
+ const onRestoreFocus = useCallback(() => {
377
+ if (!editor.isEditable) return;
378
+ const pos = nodePos();
379
+ if (pos === null) return;
380
+ const current = editor.state.doc.nodeAt(pos);
381
+ if (!current || current.type.name !== "composer-citation") return;
382
+ editor.commands.focus(pos + current.nodeSize);
383
+ }, [editor, nodePos]);
384
+
385
return (
386
<NodeViewWrapper
387
as="span"
@@ -378,6 +389,23 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
389
contentEditable={false}
390
spellCheck={false}
391
data-composer-citation-chip="true"
392
+ onKeyDown={(event: ReactKeyboardEvent<HTMLElement>) => {
393
+ // Tab from the comment button returns to the caret after the chip.
394
+ if (
395
+ !editor.isEditable ||
396
+ event.key !== "Tab" ||
397
+ event.shiftKey ||
398
+ event.altKey ||
399
+ event.metaKey ||
400
+ event.ctrlKey ||
401
+ !(event.target instanceof HTMLElement) ||
402
+ event.target.dataset.citationCommentTrigger === undefined
403
+ ) {
404
+ return;
405
+ }
406
+ event.preventDefault();
407
+ onRestoreFocus();
408
+ }}
409
>
410
<AssistantCitationChip
411
citation={citation}
@@ -396,6 +424,7 @@ function ComposerCitationNodeView({ node, editor, getPos }: NodeViewProps) {
424
commentContext.onSubmitAndSend();
425
return true;
426
},
427
+ onRestoreFocus,
428
}}
429
/>
430
</NodeViewWrapper>
@@ -856,6 +885,32 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
885
return true;
886
}
887
}
888
+ // Shift+Tab from just after a citation reaches its comment button, which
889
+ // native tab order skips because the chip lives inside the editor.
890
+ if (
891
+ event.key === "Tab" &&
892
+ event.shiftKey &&
893
+ !event.altKey &&
894
+ !event.metaKey &&
895
+ !event.ctrlKey &&
896
+ view.state.selection.empty
897
+ ) {
898
+ const { $from } = view.state.selection;
899
+ const citation = $from.nodeBefore;
900
+ if (citation?.type.name === "composer-citation") {
901
+ const chip = view.nodeDOM($from.pos - citation.nodeSize);
902
+ const commentButton =
903
+ chip instanceof HTMLElement
904
+ ? chip.querySelector<HTMLElement>("[data-citation-comment-trigger]")
905
+ : null;
906
+ if (commentButton) {
907
+ event.preventDefault();
908
+ event.stopPropagation();
909
+ commentButton.focus();
910
+ return true;
911
+ }
912
+ }
913
+ }
914
if (event.key === "Enter" && (event.isComposing || event.keyCode === 229)) {
915
event.stopPropagation();
916
return true;
apps/web/src/components/chat/AssistantCitationChip.tsx
+20
@@ -39,10 +39,13 @@ export function AssistantCitationChip({
39
onCancel?: () => void;
40
onSave: (comment: string) => boolean;
41
onSaveAndSend?: (comment: string) => boolean;
42
+ /** Returns focus to the host editor when the popover closes instead of to the pencil trigger. */
43
+ onRestoreFocus?: () => void;
44
};
45
}) {
46
const navigate = useNavigate();
47
const commentInputRef = useRef<HTMLTextAreaElement>(null);
48
+ const commentPopupRef = useRef<HTMLDivElement>(null);
49
const draftCommentRef = useRef<string | null>(null);
50
const [unavailableSourceAnchor, setUnavailableSourceAnchor] =
51
useState<AssistantCitationSourceAnchor | null>(null);
@@ -155,6 +158,7 @@ export function AssistantCitationChip({
158
>
159
<PopoverTrigger
160
aria-label={citation.comment ? "Edit citation comment" : "Add comment to citation"}
161
+ data-citation-comment-trigger="true"
162
render={<ContextChipAction />}
163
>
164
<PencilIcon aria-hidden="true" />
@@ -169,6 +173,22 @@ export function AssistantCitationChip({
173
commentInputRef.current?.focus({ preventScroll: true });
174
return false;
175
}}
176
+ finalFocus={
177
+ commentEditor.onRestoreFocus
178
+ ? () => {
179
+ // Leave focus alone when the user closed the popover by moving to another control.
180
+ const activeElement = document.activeElement;
181
+ if (
182
+ activeElement === document.body ||
183
+ (activeElement !== null && commentPopupRef.current?.contains(activeElement))
184
+ ) {
185
+ commentEditor.onRestoreFocus?.();
186
+ }
187
+ return false;
188
+ }
189
+ : undefined
190
+ }
191
+ ref={commentPopupRef}
192
aria-label="Edit citation comment"
193
width="md"
194
padding="compact"