The best way to control Claude Code, Codex and more from any computer or phone
fix(web): restore the composer caret after dictation (#38224)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Adamulek123 committed
Nov 19, 2026 at 12:55 UTC
470ca63499293f7f680f8ad2e77381a6752f1348
2 files changed
+76
-3
apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx
+50
-1
@@ -66,6 +66,7 @@ function Composer({
66
onCommandKeyDown = () => false,
67
importContextFragment,
68
literalText = false,
69
+ disabled = false,
70
}: {
71
value: string;
72
richTextEnabled: boolean;
@@ -74,6 +75,7 @@ function Composer({
75
onCommandKeyDown?: ComposerPromptEditorProps["onCommandKeyDown"] | undefined;
76
importContextFragment?: ComposerPromptEditorProps["importContextFragment"];
77
literalText?: boolean;
78
+ disabled?: boolean;
79
}) {
80
const [prompt, setPrompt] = useState({ value, cursor: value.length });
81
return (
@@ -84,7 +86,7 @@ function Composer({
86
richTextEnabled={richTextEnabled}
87
contextRecords={new Map()}
88
skills={skills}
87
- disabled={false}
89
+ disabled={disabled}
90
placeholder=""
91
onChange={(...args) => {
92
setPrompt({ value: args[0], cursor: args[1] });
@@ -1079,3 +1081,50 @@ describe("an Arabic line", () => {
1081
);
1082
});
1083
});
1084
+
1085
+it.each([true, false])(
1086
+ "restores the caret after dictation unlocks the editor (rich text: %s)",
1087
+ async (richTextEnabled) => {
1088
+ const ui = (disabled: boolean) => (
1089
+ <Composer value="Draft" richTextEnabled={richTextEnabled} skills={[]} disabled={disabled} />
1090
+ );
1091
+ await using screen = await render(ui(false));
1092
+ const editor = editorIn(screen.container);
1093
+ await act(() => {
1094
+ editor.commands.setTextSelection(3);
1095
+ editor.view.focus();
1096
+ });
1097
+ await screen.rerender(ui(true));
1098
+ await screen.rerender(ui(false));
1099
+ await vi.waitFor(() => {
1100
+ expect(editor.view.hasFocus()).toBe(true);
1101
+ expect(editor.view.dom.contains(window.getSelection()?.anchorNode ?? null)).toBe(true);
1102
+ });
1103
+ await userEvent.keyboard("X");
1104
+ await vi.waitFor(() => expect(editor.getText()).toBe("DrXaft"));
1105
+ },
1106
+);
1107
+
1108
+it.each(["other field", "document body"])(
1109
+ "does not reclaim focus when it moves away during dictation and ends on the %s",
1110
+ async (focusTarget) => {
1111
+ const ui = (disabled: boolean) => (
1112
+ <>
1113
+ <Composer value="Draft" richTextEnabled skills={[]} disabled={disabled} />
1114
+ <input aria-label="Other field" />
1115
+ </>
1116
+ );
1117
+ await using screen = await render(ui(false));
1118
+ const editor = editorIn(screen.container);
1119
+ await act(() => editor.view.focus());
1120
+ await screen.rerender(ui(true));
1121
+ const other = screen.container.querySelector("input")!;
1122
+ other.focus();
1123
+ await vi.waitFor(() => expect(document.activeElement).toBe(other));
1124
+ if (focusTarget === "document body") other.blur();
1125
+ await screen.rerender(ui(false));
1126
+ await vi.waitFor(() =>
1127
+ expect(document.activeElement).toBe(focusTarget === "document body" ? document.body : other),
1128
+ );
1129
+ },
1130
+);
apps/web/src/components/ComposerPromptEditorTiptap.tsx
+26
-2
@@ -1534,9 +1534,33 @@ function ComposerPromptEditorTiptapInner(
1534
[],
1535
);
1536
1537
- // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- pushes the disabled prop into the imperative Tiptap editor via setEditable
1537
+ const resumeEditingFocusRef = useRef(false);
1538
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- preserves native selection focus across temporarily making the editor read-only for dictation
1539
useEffect(() => {
1539
- editor?.setEditable(!disabled);
1540
+ if (!editor) return;
1541
+ if (disabled && editor.isEditable) resumeEditingFocusRef.current = editor.view.hasFocus();
1542
+ editor.setEditable(!disabled);
1543
+ if (!resumeEditingFocusRef.current) return;
1544
+
1545
+ const editorDom = editor.view.dom;
1546
+ const ownerDocument = editorDom.ownerDocument;
1547
+ if (disabled) {
1548
+ const cancelFocusRestore = (event: FocusEvent) => {
1549
+ if (!event.composedPath().includes(editorDom)) {
1550
+ resumeEditingFocusRef.current = false;
1551
+ }
1552
+ };
1553
+ ownerDocument.addEventListener("focusin", cancelFocusRestore, true);
1554
+ return () => ownerDocument.removeEventListener("focusin", cancelFocusRestore, true);
1555
+ }
1556
+
1557
+ resumeEditingFocusRef.current = false;
1558
+ if (
1559
+ ownerDocument.activeElement === ownerDocument.body ||
1560
+ ownerDocument.activeElement === editorDom
1561
+ ) {
1562
+ editor.view.focus();
1563
+ }
1564
}, [disabled, editor]);
1565
1566
// Push attributes before layout measurements; Tiptap updates them later in a passive effect.