Skip to content

Commit edbd9f3

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 5cc99e1 commit edbd9f3

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
@@ -1175,7 +1175,11 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
11751175
const focusAt = useCallback(
11761176
(nextCursor: number) => {
11771177
if (!editor) return;
1178-
editor.view.dom.focus({ preventScroll: true });
1178+
// view.focus() writes the state selection to the DOM as it focuses. A
1179+
// bare DOM focus leaves the native caret at the start until
1180+
// ProseMirror resyncs it 20ms later, and dictation tools type fast
1181+
// enough to land keys there, ahead of the text already inserted.
1182+
editor.view.focus();
11791183
// A newer prompt is waiting to be applied (a chip was just inserted
11801184
// through the store). Reporting the editor's stale text now would
11811185
// overwrite that prompt; the pending rewrite places the caret instead.

0 commit comments

Comments
 (0)