Skip to content

Commit 177fcdc

Browse files
committed
fix(web): fast typing no longer scrambles text when type-to-focus kicks in
When the composer is blurred, the first keystroke is redirected into the draft and the editor is focused a frame later. That focus used a bare DOM focus, which leaves the native caret at the start of the editor until ProseMirror resyncs it about 20ms later. Voice dictation tools such as whisrs type faster than that, so the next keys landed ahead of the redirected text ("Testing 1, 2, 3." became ", 3.Testing 1, 2"). Focus through ProseMirror's view.focus(), which writes the state selection to the DOM as it focuses, so the caret is at the end before the next key arrives.
1 parent f570bd2 commit 177fcdc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,11 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
12101210
const focusAt = useCallback(
12111211
(nextCursor: number) => {
12121212
if (!editor) return;
1213-
editor.view.dom.focus({ preventScroll: true });
1213+
// view.focus() writes the state selection to the DOM as it focuses. A
1214+
// bare DOM focus leaves the native caret at the start until
1215+
// ProseMirror resyncs it 20ms later, and dictation tools type fast
1216+
// enough to land keys there, ahead of the text already inserted.
1217+
editor.view.focus();
12141218
// A newer prompt is waiting to be applied (a chip was just inserted
12151219
// through the store). Reporting the editor's stale text now would
12161220
// overwrite that prompt; the pending rewrite places the caret instead.

0 commit comments

Comments
 (0)