editor: stop focus dragging the view back to the caret on load

This commit is contained in:
Ammar Ahmed
2026-08-27 13:58:31 +05:00
parent b2856374a3
commit 5220a1704e
2 changed files with 7 additions and 2 deletions

View File

@@ -298,7 +298,10 @@ function TipTap(props: TipTapProps) {
element: editorContainer(),
editable: !readonly,
content: content?.(),
autofocus: "start",
// Tiptap's autofocus scrolls to the caret a frame after the editor is
// created, which would undo the restored scroll position. The caret is
// placed by the selection restore instead.
autofocus: false,
onFocus,
onCreate: async ({ editor }) => {
setProfiledEditor(editor as Editor);

View File

@@ -70,7 +70,9 @@ export const useEditor = (
editor.createView();
});
}
if (oldIsFocused && !editor.isFocused) editor.commands.focus();
// Restoring focus must not drag the view to the caret.
if (oldIsFocused && !editor.isFocused)
editor.commands.focus(null, { scrollIntoView: false });
// The Editor constructor emits `create` for the view it made, so calling
// the option here as well would run every consumer twice on load.
if (!firstRun) options.onCreate?.({ editor: editor });